[LLVMbugs] [Bug 10898] New: extraneous parentheses warnings

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Sep 9 14:58:09 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=10898

           Summary: extraneous parentheses warnings
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: neal.meyer at riverbed.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


Just updated to Xcode 4.2 beta 7.

I have the following code.
int buf_plus_null = 3 + 3 + unicode() ? 2 : 0;

Produced the following warning:


warning: operator '?:' has lower
      precedence than '+'; '+' will be evaluated first [-Wparentheses]
        int buf_plus_null = 3 + 3 + unicode() ? 2 : 0;
                            ~~~~~~~~~~~~~~~~~ ^
XYZ.h:925:47: note: place parentheses around the '+'
      expression to silence this warning
        int buf_plus_null = 3 + 3 + unicode() ? 2 : 0;
                                              ^
                            (                )
XYZ.h:925:47: note: place parentheses around the '?:'
      expression to evaluate it first
        int buf_plus_null = 3 + 3 + unicode() ? 2 : 0;
                                              ^
                                    (                )


Updated the code to have the proper parentheses to the following (Suggestion
1):
int buf_plus_null = (3 + 3 + unicode()) ? 2 : 0;

The following warning is produced:
 warning: operator '?:' has lower
      precedence than '+'; '+' will be evaluated first [-Wparentheses]
        int buf_plus_null = (3 + 3 + unicode()) ? 2 : 0;
                            ~~~~~~~~~~~~~~~~~~~ ^
XYZ.h:925:49: note: place parentheses around the '+'
      expression to silence this warning
        int buf_plus_null = (3 + 3 + unicode()) ? 2 : 0;
                                                ^
                            (                  )
XYZ.h:925:49: note: place parentheses around the '?:'
      expression to evaluate it first
        int buf_plus_null = (3 + 3 + unicode()) ? 2 : 0;
                                                ^
                                     (                 )

The 2nd suggestion is syntactically incorrect, and the 1st seems un-necessarily
verbose.  Suggestion 1 also does not fix the warning.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list