Search code examples
c++visual-c++c++20consteval

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?


Solution

  • 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