[PATCH] -Wcomma, a new warning for questionable uses of the comma operator

Richard Trieu rtrieu at google.com
Fri May 30 20:03:17 PDT 2014


-Wcomma emits a warning when there is a questionable use of the comma operator.  It does this by only allowing certain expressions on the LHS of the comma operator, with all other expressions giving a warning.  The current whitelisted expressions are increments, decrements, assignments, compound assignments, overloaded versions of these operators, and void returning functions.  Some examples of code that will be detected:

  int foo();
  if (foo(), 5) {} // should be "=="
  cout << "foo is " , foo();  // should be "<<"
  
  void bar(int);
  void bar(int, int);
  bar((foo(), foo()));  // Too many parens, calls the one argument function

http://reviews.llvm.org/D3976

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaExpr.cpp
  test/SemaCXX/warn-comma-operator.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3976.9977.patch
Type: text/x-patch
Size: 7550 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140531/a706198c/attachment.bin>


More information about the cfe-commits mailing list