prapin
prapin

Reputation: 6897

Cannot use consteval functions inside initializer list on MSVC

Consider that minimized code snippet:

#include <vector>

class Bar
{
public:
    constexpr Bar() {}
};

consteval Bar foo()
{
    return Bar();
}

int main()
{
    std::vector<Bar> bars{ foo(), foo() };
}

This doesn't compile on latest MSVC compiler (Visual Studio 2022 version 17.3.3), but does on Clang or GCC.

Compiler Explorer

Is the code somewhere ill formed, or it is a bug in MSVC?

Upvotes: 15

Views: 881

Answers (1)

prapin
prapin

Reputation: 6897

From the comments, it looks like this is indeed a bug in MSVC.

Therefore I filled in a bug report on Visual Studio Community.

https://developercommunity.visualstudio.com/t/Cannot-use-consteval-functions-returning/10145209

Upvotes: 10

Related Questions