13

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?

digito_evo
  • 3,216
  • 2
  • 14
  • 42
prapin
  • 6,395
  • 5
  • 26
  • 44

1 Answers1

9

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

prapin
  • 6,395
  • 5
  • 26
  • 44
  • In my Visual Studio 2022, gave compile error `error C7595: 'foo': call to immediate function is not a constant expression` – daparic Sep 12 '22 at 15:33