0

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
xmllmx
  • 39,765
  • 26
  • 162
  • 323

1 Answers1

2

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

Spock77
  • 3,256
  • 2
  • 30
  • 39
  • My compiler is VC++ 2013 CTP, rather than VC++ 2013. – xmllmx Feb 20 '14 at 04:58
  • 1
    According to [this article](http://blogs.msdn.com/b/vcblog/archive/2013/11/18/announcing-the-visual-c-compiler-november-2013-ctp.aspx), the support of constexpr in 2013 CTP is "except for member functions". – Spock77 Feb 20 '14 at 06:58