On Tue, 26 Nov 2024 at 18:16, Marc Glisse <marc.gli...@inria.fr> wrote:
>
> On Tue, 26 Nov 2024, Jonathan Wakely wrote:
>
> >>> In the bla() example above, the call bla() is a constant expression
> >>> when used to initialize a const int, so the compiler is required to
> >>> evaluate it at compile time.
> >>
> >> When used in contexts that doesn't require an integral constant I think a
> >> distinction between evaluating at compile time or at run time can't be
> >> observed.
> >
> > Agreed.
>
> Can't be observed might be a bit strong?
>
> constexpr int f(){
>    if consteval {return 1;} else {return 2;}
> }
> int main(){
>    int a=f();
>    const int b=f();
>    return a+b;
> }
>
> returns 3 (and clang agrees).

Sure, if the function intentionally changes behaviour. That's pretty
gross though.

Reply via email to