Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does adding constexpr make VS2013 reject this?

This code does not compile in Visual Studio 2013

template <typename X> 
constexpr //error C2144: syntax error : 'bool' should be preceded by ';'
bool Test(X x)
{
    return true;
}

However, if I remove the constexpr keyword, it does compile.

But constexpr shouldn't be a problem? since it always returns true.

What went wrong?

like image 525
athos Avatar asked Jul 14 '26 03:07

athos


1 Answers

Despite the 2013 in the name, VS2013 does not purport to be a compiler targeting the C++11 standard (which was when constexpr was introduced).

The value of __cplusplus will be 201103L for a C++11 compiler.

So your compiler encounters a token it does not recognise, and issues a diagnostic.

like image 60
Bathsheba Avatar answered Jul 15 '26 16:07

Bathsheba