From: Vladimir Grigoriev on
After I set on the "Diasble Language Extension" option I get the following
warning

warning C4180: qualifier applied to function type has no meaning; ignored

for the statement



template <typename T>

inline const T operator -( const T &lhs, const T &rhs )

{

return ( T( lhs ) -= rhs );

}



The comment for this warning is saying about typedef. However it is not a
typedef but a template.



Why is const qualifier ignored?



Vladimir Grigoriev


From: Victor Bazarov on
Vladimir Grigoriev wrote:
> After I set on the "Diasble Language Extension" option I get the following
> warning
>
> warning C4180: qualifier applied to function type has no meaning; ignored
>
> for the statement
>
>
>
> template <typename T>
>
> inline const T operator -( const T &lhs, const T &rhs )
>
> {
>
> return ( T( lhs ) -= rhs );
>
> }
>
>
>
> The comment for this warning is saying about typedef.

Huh?

> However it is not a
> typedef but a template.
>
>
>
> Why is const qualifier ignored?

The return value from this function is an r-value. R-values of
non-class types cannot be cv-qualified.

Next time when posting a question about a template, consider including
the code that *uses* that template, and causes the template to be
instantiated.

Good luck!

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
From: Igor Tandetnik on
Victor Bazarov wrote:
> Next time when posting a question about a template, consider including
> the code that *uses* that template, and causes the template to be
> instantiated.

In this particular case, the warning is produced even if the template is never used. This complete program reproduces the issue:

template <typename T> const T f();
int main() { return 0; }

"const" in the return type is meaningful at least for some possible values of T. The warning does look spurious to me.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
From: Vladimir Grigoriev on
Victor, as Igor Tandetnik has noted the compiler issues the warning
referencing to the template definition irrespective of its using.

Vladimir Grigoriev

"Victor Bazarov" <v.Abazarov(a)comAcast.net> wrote in message
news:hgg1t9$343$1(a)news.datemas.de...
> Vladimir Grigoriev wrote:
>> After I set on the "Diasble Language Extension" option I get the
>> following warning
>>
>> warning C4180: qualifier applied to function type has no meaning; ignored
>>
>> for the statement
>>
>>
>>
>> template <typename T>
>>
>> inline const T operator -( const T &lhs, const T &rhs )
>>
>> {
>>
>> return ( T( lhs ) -= rhs );
>>
>> }
>>
>>
>>
>> The comment for this warning is saying about typedef.
>
> Huh?
>
> > However it is not a
>> typedef but a template.
>>
>>
>>
>> Why is const qualifier ignored?
>
> The return value from this function is an r-value. R-values of non-class
> types cannot be cv-qualified.
>
> Next time when posting a question about a template, consider including the
> code that *uses* that template, and causes the template to be
> instantiated.
>
> Good luck!
>
> V
> --
> Please remove capital 'A's when replying by e-mail
> I do not respond to top-posted replies, please don't ask


From: sasha on
Igor Tandetnik wrote:

> "const" in the return type is meaningful at least for some possible values of T. The warning does look spurious to me.


FWIW, this code compiles fine with MSC, without any diagnostics. This
causes some type conversions 'disablement', which seems incorrect.

class t
{
operator bool();
operator const bool();
};