https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97681

--- Comment #5 from Luke Dalessandro <ldalessandro at gmail dot com> ---
The more I think about this the more it bothers me. 

I recognize that it might be very difficult to implement in gcc's
infrastructure, but I think the design decision that "if it _can_ be constant
evaluated it _will_ be constant evaluated" is too aggressive.

Consider https://godbolt.org/z/cTYPaK.

```
[[gnu::noinline]]
constexpr int a(int x) { 
    return x + 1; 
}

int main() {
    int i = a(1);
    return i;
}
```

1. The function is marked noinline.
2. The code is compile with "-O0 -g".
3. The calling context is not explicitly `constexpr`.

The fact that gcc _still_ chooses to constant evaluate `a` at best violates the
principle of least surprise, and at worst makes it impractical to use gcc to
debug more complex codebases. Honestly, the `noinline` annotation shouldn't
even be necessary, `a` should simply not be constant evaluated with `-O0`. It's
not practical to find all of the uses of `a` and modify their call sites.

>From a software engineering perspective I believe that gcc must provide some
way to disable this behavior.

Reply via email to