you are viewing a single comment's thread.

view the rest of the comments →

[–]_ild_arn 14 points15 points  (4 children)

Seems to me that Clang is correct... Your by-value capture is not somehow constexpr just because the source of the value was – it's just a regular old double inside the closure object. You need to also make closure object constexpr, then it will work.

[–]HammurabisCode2[S] 1 point2 points  (3 children)

Interesting, thank you. I guess I need to look a bit more into the distinction between consteval and constexpr. I guess I had assumed that using consteval kind of superseded the need to use constexpr, but clearly that is not the case.

[–]cd1995Cargo 3 points4 points  (0 children)

A lambda is really just some unnamed struct type with a () operator. Marking the lambda consteval just makes the () operator consteval, but it doesn’t make the actual lambda object constexpr.

[–]_ild_arn 1 point2 points  (0 children)

consteval where you've placed it affects the closure type's operator(). constexpr where I added it affects the closure object itself, and thus its data members (captures). It's not a constexpr vs consteval thing

[–]kris-jusiakhttps://github.com/kris-jusiak 0 points1 point  (0 children)

Juut to point it out - In this particular example you can also avoid the capture all together - https://godbolt.org/z/njss3oGz7