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

            Bug ID: 126068
           Summary: Empty second operand to the conditional operator in
                    the preprocessor
           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: ---

I don't see a good reason to disallow the compact version of the conditional
operator in the preprocessor.  This bug was reported by a C Committee member
while reviewing n3905, which attempts to standardize this feature.


alx@devuan:~/tmp$ cat pp.c 
#if defined(X) ? 1 : 0
# warning a
#else
# warning b
#endif

#if defined(X) ?: 0
# error a
#else
# error b
#endif
alx@devuan:~/tmp$ gcc pp.c 
pp.c:4:3: warning: #warning b [-Wcpp]
    4 | # warning b
      |   ^~~~~~~
pp.c:7:17: error: operator ‘?’ has no right operand
    7 | #if defined(X) ?: 0
      |                 ^
pp.c:10:3: error: #error b
   10 | # error b
      |   ^~~~~
alx@devuan:~/tmp$ gcc -DX pp.c 
pp.c:2:3: warning: #warning a [-Wcpp]
    2 | # warning a
      |   ^~~~~~~
pp.c:7:17: error: operator ‘?’ has no right operand
    7 | #if defined(X) ?: 0
      |                 ^
pp.c:10:3: error: #error b
   10 | # error b
      |   ^~~~~

Reply via email to