Visual C ++ 2015 gives warning C4552 when using decltype (auto)

I think I encountered an error in Visual C ++ 2015, but I want to be sure. Consider this snippet:

template < typename T > decltype( auto ) f( T param ) { return param + 1; } int main() { auto i = f( 10 ); return 0; } 

Visual C ++ 2015 gives this warning in the return statement:

warning C4552: '+': operator is not valid; expected operator with side effect

although it does not seem to affect the resulting code. Is this a compiler error?

+5
source share
3 answers
+3
source

As mentioned in the Csq answer , the observed behavior is pending a Microsoft Connect report . This question has not been rated yet.

To get around the problem 1) you can include parentheses around the expression:

 template < typename T > decltype( auto ) f( T param ) { return ( param + 1 ); } 


1) Tested using Visual Studio 2015 Community Edition
+2
source

As pointed out by Microsoft itself here , this could be a β€œbug”. Try:

 decltype(auto) f(T param) { return (param + 1); } 

Or simply suppress this war, because Microsoft probably won't fix it because of their β€œmistaken” excuses.

+1
source

All Articles