https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106448
Bug ID: 106448
Summary: [OpenMP] atomic compare – g++ wrongly accepts
parenthesized condition
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Keywords: accepts-invalid, diagnostic, openmp
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: burnus at gcc dot gnu.org
CC: jakub at gcc dot gnu.org
Target Milestone: ---
The following code is rejected by gcc - but accepted by g++.
(Found via OpenMP examples Issue #291.)
OpenMP permits:
x = expr ordop x ? expr : x;
x = x ordop expr ? expr : x;21
x = x == e ? d : x;
If one now parenthesis the condition, gcc rightly complains:
error: invalid form of ‘#pragma omp atomic’ before ‘;’ token
7 | x = (expr > x) ? expr : x;
| ^
However, g++ accepts that version without an error.
Note that g++ rejects the reverse version already:
error: invalid form of ‘#pragma omp atomic’ before ‘(’ token
10 | x = (x < expr) ? expr : x; // Rejected by g++ and gcc
| ^
--------------
int x, expr;
void
foo (void)
{
#pragma omp atomic compare
x = (expr > x) ? expr : x; // Accepted by g++ [BUG!], rejected by gcc
#pragma omp atomic compare
x = (x < expr) ? expr : x; // Rejected by g++ and gcc
#pragma omp atomic compare
x = (x == expr) ? expr : x; // Rejected by g++ and gcc
}