Question Details

No question body available.

Tags

c++ c++20

Answers (2)

Accepted Answer Available
Accepted Answer
April 2, 2026 Score: 4 Rep: 41,141 Quality: High Completeness: 70%

Possible workaround, so you can address issue until bug is fixed and you upgrade your compiler:

int main()
{
    static constexpr auto x = ConstEval{1};
    [[maybe_unused]]HasConstEval y{
        .ceval = x
    };
}

https://godbolt.org/z/qWoTE6xed

Looks like MSVC is trying to create temporary object instead instantiate it at compile time and then use it as argument.

In above workaround static compile time constant is instantiated explicitly.

Note it is a good practice to use named constants.

April 2, 2026 Score: 10 Rep: 1,083 Quality: Low Completeness: 30%

Since the comments suggested this might be an issue with msvc itself, I asked this question in the vs developer community. It is a bug in VS and it is fixed in VS 2026.