Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 379
prapin Avatar asked Jan 28 '26 21:01

prapin


1 Answers

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

like image 97
prapin Avatar answered Jan 31 '26 11:01

prapin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!