Discussion:
Warning C4180 in Visual C++ 2005 EE
(too old to reply)
Vladimir Grigoriev
2009-12-18 13:45:45 UTC
Permalink
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
Victor Bazarov
2009-12-18 14:00:08 UTC
Permalink
Post by Vladimir Grigoriev
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?
Post by Vladimir Grigoriev
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
Igor Tandetnik
2009-12-18 14:14:04 UTC
Permalink
Post by Victor Bazarov
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
sasha
2009-12-19 00:40:47 UTC
Permalink
Post by Igor Tandetnik
"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();
};
Victor Bazarov
2009-12-19 19:25:36 UTC
Permalink
Post by sasha
Post by Igor Tandetnik
"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();
};
It's not the same, is it? Don't declare a conversion function, declare
a regular function even if it is an operator:

bool operator()();

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Vladimir Grigoriev
2009-12-18 15:41:52 UTC
Permalink
Victor, as Igor Tandetnik has noted the compiler issues the warning
referencing to the template definition irrespective of its using.

Vladimir Grigoriev
Post by Vladimir Grigoriev
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?
Post by Vladimir Grigoriev
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
Loading...