https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122050
Waffl3x <waffl3x at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |waffl3x at gcc dot gnu.org
--- Comment #6 from Waffl3x <waffl3x at gcc dot gnu.org> ---
(In reply to Alejandro Colomar from comment #5)
> 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.
Per this PR, this code is not portable with C++, it fails in C++ mode
in both GCC and Clang. IMO the code is clearly wrong as _Pragma does
not require a semicolon.
(In reply to Richard Biener from comment #2)
> I think the current behavior of the C frontend doesn't make sense and is
> inconsistent. Of course fixing it might break existing code ... I'd suggest
> to emit a pedantic error if the 2nd last stmt isn't 'void' as well.
However I agree we should preserve the behavior, at least for now. I
reckon the question is where to draw the line.
I can think of 4 cases:
1. Empty statements after any non-void statements.
```
({
int a = 0;
a;
; // error/warning
});
({
int a = 0;
++a;
; // error/warning
});
```
2. Statements of type void (non-empty) after any non-void statements.
```
int g ();
({
int a = 0;
a;
(void)g (); // error/warning
});
({
int a = 0;
++a;
(void)g (); // error/warning
});
```
3. Statements of type void after a non-void statement...
a. ...without side effects.
```
void f ();
({
int a = 0;
a;
f (); // error/warning
});
```
3b. ...with side effects.
```
void f ();
({
int a = 0;
++a;
f (); // error/warning
});
```
I think cases 1 and 3a should be diagnosed, while 2b could possibly
have false positives. I could also see case 2 being diagnosed. I can
draft a patch for whichever we select. Obviously the safest is to only
warn/error for the first case (empty statements).