Search code examples
c++visual-c++c++11language-featuresc++14

Why can constexpr not apply to constructors?


Why can constexpr not apply to constructors?

The following code cannot be compiled with VC++ 2013 CTP.

struct A
{
    constexpr A()
        : _n(5)
    {}

    int _n;
};

constexpr A f()
{
    return A();
}

int main()
{
    auto a = f();
}

error C3757: 'A': type not allowed for 'constexpr' function

Solution

  • VC 2013 does not support all C++11 features yet. Look at MSDN list.