smallB
smallB

Reputation: 17148

Function returning constexpr does not compile

Why doesn't this compile:
Could there be a problem with a string as a return type?

constexpr std::string fnc()
{
    return std::string("Yaba");
}

Upvotes: 11

Views: 1905

Answers (1)

R. Martinho Fernandes
R. Martinho Fernandes

Reputation: 234674

The constructor of std::string that takes a pointer to char is not constexpr. In constexpr functions you can only use functions that are constexpr.

Upvotes: 14

Related Questions