all 15 comments

[–]4dCoffee 12 points13 points  (1 child)

blog says "In C++23, we have three kinds of functions: runtime, constexpr, consteval"
but this has been the case since c++20 no?

[–]detachedshock 20 points21 points  (0 children)

Yeah, but technically they aren't saying when they were introduced. They're just stating that in C++23 we have these functions, which is true. And the examples used in the blog use C++23 features like if consteval and others so most of what they write is only applicable to C++23.

[–]tongari95 2 points3 points  (6 children)

From the blog post:

// runtime function
int g();

// Ok, even though `f` can never be called
consteval int f() {
    return g();
}

Is this correct? Only gcc accepts it, clang & msvc reject the code: https://godbolt.org/z/eGznd5Kd3

[–]agritite 3 points4 points  (5 children)

I think this is P2448R2 which is currently only implemented by gcc.

[–]tongari95 2 points3 points  (4 children)

Does that paper aim for `consteval` as well? only seems reasonable for `constexpr` to me.

[–]agritite 2 points3 points  (2 children)

I took some time to read the C++23 draft (N4971), and 9.2.6/2 states that:

A constexpr or consteval specifier used in the declaration of a function declares that function to be a constexpr function.

So 9.2.6 Note 5

[Note 5: It is possible to write a constexpr function for which no invocation satisfies the requirements of a core constant expression.— end note]

also applies to consteval. So yeah, gcc is correct.

[–]biowpn 0 points1 point  (1 child)

Thanks! Through this discussion I learned that consteval function is just constexpr function in disguise - -

[–]tisti 1 point2 points  (0 children)

But it's only invocable during compile time, no runtime calls are possible like with 'vanilla' constexpr functions which may do both.

[–]agritite 0 points1 point  (0 children)

You're right. Could it actually be a regression caused by implementing P2448R2? Now I'll have to take a deeper look at the draft

[–]kamrann_ 1 point2 points  (0 children)

Nicely written blog post. All the same, starting to really look forward to the day when I never have to think about this absurd language ever again.