The ?: operators are supposed to group right.  In gcc they do, but in cpp they
do not (i.e., they seem to group left in #if statements).

Example:

#include <iostream>
using std::hex;
using std::dec;
using std::cout;
using std::endl;
int main()
{
#   if ( 1 ? 0x0DFFFFFF : 3 < 5 ? 1ull << 36 : 1ull << 40 ) <= 0xDFFFFFFF
    cout << "OK GROUPING" << endl;
#   else
#   error BAD GROUPING
#   endif
#   if ( 1 ? 0x0DFFFFFF : ( 3 < 5 ? 1ull << 36 : 1ull << 40 ) ) <= 0xDFFFFFFF
    cout << "OK WITH UNNESSARY PARENTHESES" << endl;
#   else
#   error BAD WITH UNNECESSARY PARENTHESES
#   endif
}

This outputs the BAD GROUPING error.


-- 
           Summary: ?: operator incorrectly groups left in cpp
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: walton at seas dot harvard dot edu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40241

Reply via email to