News for hackers. Stuff that matters.
Re:Proposal to add constexpr to C [pdf] by boulos on Saturday October 16, 2021 @02:14PM (#28890033)
... constexpr isn't superfluous.

The compiler can/could/does absolutely infer that a thing is a compile time constant and do it for you.

But, if you declare a thing constexpr and someone updates some part of it to be !constexpr, you get a nice compiler error. Without labeling the value as constexpr, you don't get that certainty.

Edit: is the argument that const static is also that? (If so, only for direct initialization of structures / you still can't have the equivalent of a constexpr function).

Re:Proposal to add constexpr to C [pdf] by dataflow on Saturday October 16, 2021 @03:06PM (#28890492)
> But, if you declare a thing constexpr and someone updates some part of it to be !constexpr, you get a nice compiler error. Without labeling the value as constexpr, you don't get that certainty.

That's not really true. You don't get that "certainty" with constexpr either:

  template<class T> T f(T);
  template<class T> constexpr T g(T x) { return f(x); }
Notice you won't even get a warning with -Weverything under Clang!

> Edit: is the argument that const static is also that? (If so, only for direct initialization of structures / you still can't have the equivalent of a constexpr function).

For variables, const static should probably evaluate at compile time whenever possible, like you mentioned.

For functions, constexpr is really useless (again, see above as just one example) and an inline declaration serves pretty much the same practical purpose. I think you're thinking of 'consteval', which is at least not completely useless, so it's a little easier to justify. Even then, it should've probably been an attribute rather than a keyword.

Re:Proposal to add constexpr to C [pdf] by boulos on Saturday October 16, 2021 @09:47PM (#28893275)
Hmm, is that just because of the template resolution? (and so wouldn't apply to constexpr in C)

AFAICT, something about the template declarations is making the call of f(x) to be "who could know" (which should just be fail).

The same thing with concrete types says that f isn't constexpr [3]. And you have to make it actually constexpr by removing the static from counter [4].

[1] https://docs.microsoft.com/en-us/cpp/cpp/constexpr-cpp?view=...

[2] https://godbolt.org/z/7rGWbP1xz

[3] https://godbolt.org/z/5WjMr3Kjv

[4] https://godbolt.org/z/v9rc1j9zc

Re:Proposal to add constexpr to C [pdf] by dataflow on Saturday October 16, 2021 @10:13PM (#28893388)
I think it's because of ADL, which also wouldn't apply in C.
Re:Proposal to add constexpr to C [pdf] by dataflow on Sunday October 17, 2021 @03:19PM (#28898975)
Edit: Actually maybe I'm wrong... even if you scope it it won't warn you.