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

            Bug ID: 122721
           Summary: Fold more aggressively in static_assert(3)
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: [email protected]
  Target Milestone: ---

It would be good to be able to statically assert conditions that are known at
compile time, even if they involve run-time variables, when optimizations are
high enough.

The most obvious program is:

```
alx@devuan:~/tmp$ cat sa.c
int
main(int argc, char *[])
{
        int n = argc;

        static_assert(n == argc);
}
```
```
alx@devuan:~/tmp$ gcc sa.c -O3
sa.c: In function ‘main’:
sa.c:6:25: error: expression in static assertion is not constant
    6 |         static_assert(n == argc);
      |                       ~~^~~~~~~
```

Here, the compiler should be able to verify that n==argc is true, so rejecting
this code is unnecessary.

Reply via email to