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
4
  • 3
    I thought MSVC only supported non-member constexpr functions. Commented Feb 19, 2014 at 10:59
  • 5
    Basically because VC++ doesn't support it. Commented Feb 19, 2014 at 11:05
  • Indeed, that wouldn't be a problem for another compiler such as GCC. Commented Feb 19, 2014 at 11:21
  • msdn.microsoft.com/en-us/library/hh567368.aspx Commented Feb 19, 2014 at 11:46

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

My compiler is VC++ 2013 CTP, rather than VC++ 2013.
According to this article, the support of constexpr in 2013 CTP is "except for member functions".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.