https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122721
Alejandro Colomar <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|WONTFIX |FIXED --- Comment #2 from Alejandro Colomar <[email protected]> --- (In reply to Andrew Pinski from comment #1) > That is not statically know at all. Would requires a full flow analysis > which the front end does not have. Hmmm, actually, this is already possible, with a simple macro, and a GCC attribute. ``` alx@devuan:~/tmp$ cat sa.c #define compiler_assert(e) do \ { \ [[gnu::error("")]] extern void fail_(void); \ \ if (!e) \ fail_(); \ } while (0) int main(int argc, char *[]) { int n = argc; __COUNTER__; compiler_assert(n == argc); compiler_assert(n == argc + 1); } ``` ``` alx@devuan:~/tmp$ gcc -O0 sa.c sa.c: In function ‘main’: sa.c:6:17: error: call to ‘fail_’ declared with attribute error: 6 | fail_(); \ | ^~~~~~~ sa.c:15:9: note: in expansion of macro ‘compiler_assert’ 15 | compiler_assert(n == argc); | ^~~~~~~~~~~~~~~ sa.c:6:17: error: call to ‘fail_’ declared with attribute error: 6 | fail_(); \ | ^~~~~~~ sa.c:16:9: note: in expansion of macro ‘compiler_assert’ 16 | compiler_assert(n == argc + 1); | ^~~~~~~~~~~~~~~ ``` ``` alx@devuan:~/tmp$ gcc -O1 sa.c sa.c: In function ‘main’: sa.c:6:17: error: call to ‘fail_’ declared with attribute error: 6 | fail_(); \ | ^~~~~~~ sa.c:16:9: note: in expansion of macro ‘compiler_assert’ 16 | compiler_assert(n == argc + 1); | ^~~~~~~~~~~~~~~ ``` No need for support in static_assert().
