[llvm-bugs] [Bug 34363] New: Missing diagnostics about unsequenced modifications and unintentional assignments

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Aug 29 11:55:21 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=34363

            Bug ID: 34363
           Summary: Missing diagnostics about unsequenced modifications
                    and unintentional assignments
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: hans at chromium.org
                CC: llvm-bugs at lists.llvm.org

Some interesting cases from a Chromium bug report:
https://bugs.chromium.org/p/chromium/issues/detail?id=760070

$ cat /tmp/a.cc
void f(int x, int y) {
  bool b = (x == y) ? 42 : b = 43;
  bool c = c = y == 42;
}


$ bin/clang -c -Weverything /tmp/a.cc
/tmp/a.cc:1:6: warning: no previous prototype for function 'f'
[-Wmissing-prototypes]
void f(int x, int y) {
     ^
1 warning generated.


$ gcc -c -Wall /tmp/a.cc
/tmp/a.cc: In function ‘void f(int, int)’:
/tmp/a.cc:2:32: warning: operation on ‘b’ may be undefined [-Wsequence-point]
   bool b = (x == y) ? 42 : b = 43;
                                ^
/tmp/a.cc:4:21: warning: operation on ‘c’ may be undefined [-Wsequence-point]
   bool c = c = y == 42;
                     ^



Sequence points aside, perhaps it would make sense to warn (and suggest
parenthesis) about the right-hand side assignment like we do in if-statements?

$ cat /tmp/a.cc
bool f(int x, int y) {
  bool b = x = y;
  return b;
}
$ bin/clang -c -Weverything /tmp/a.cc
/tmp/a.cc:1:6: warning: no previous prototype for function 'f'
[-Wmissing-prototypes]
bool f(int x, int y) {
     ^
1 warning generated.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170829/dce982d3/attachment.html>


More information about the llvm-bugs mailing list