Why can't I declare a string constexpr in MSVC?

Viewed 46

According to this question and other sources, most constructors for std::string are constexpr as of C++20.

Below, I attempt to use constructor (5) from here:

#include <iostream>
#include <string>

int main() {
    constexpr std::string example{ "word" };
    std::cout << example;
}

I ran this in Microsoft Visual Studio Community 2019 Version 16.11.4 with both /std:c++20 and /std:c++lastest enabled.

Both give the error

error C2131: expression did not evaluate to a constant
message : failure was caused by allocated storage not being deallocated

According to row "constexpr std::string" in this table, the feature should be present.

Am I doing something wrong? Has this feature been implemented?

0 Answers
Related