[Bug c/122050] statement expressions with an empty expression at the end have different behavior between C and C++
foss+gcc@alejandro-colomar.es
gcc-bugzilla@gcc.gnu.org
Mon Jun 1 21:21:20 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122050
Alejandro Colomar <foss+gcc@alejandro-colomar.es> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |foss+gcc@alejandro-colomar.
| |es
--- Comment #5 from Alejandro Colomar <foss+gcc@alejandro-colomar.es> ---
Consider this case:
alx@devuan:~/tmp$ cat foo.c
#define foo(x) \
({ \
_Pragma("GCC diagnostic push"); \
x; \
_Pragma("GCC diagnostic pop"); \
})
int
main(void)
{
return foo(42);
}
When the _Pragma() is removed, the trailing semicolon remains there. If the C
behavior were wrong, this code would suddenly fail.
This code has been historically portable, and IMO should remain valid.
alx@devuan:~/tmp$ gcc-11 -Wall -Wextra foo.c; ./a.out; echo $?
42
alx@devuan:~/tmp$ gcc-16 -Wall -Wextra foo.c; ./a.out; echo $?
42
alx@devuan:~/tmp$ clang-18 -Wall -Wextra foo.c; ./a.out; echo $?
42
alx@devuan:~/tmp$ clang-21 -Wall -Wextra foo.c; ./a.out; echo $?
42
More information about the Gcc-bugs
mailing list