arphaman created this revision.

Right now -Wcomma is too strict IMO, we shouldn't warn about expressions that 
return void.


Repository:
  rL LLVM

https://reviews.llvm.org/D34810

Files:
  lib/Sema/SemaExpr.cpp
  test/SemaCXX/warn-comma-operator.cpp


Index: test/SemaCXX/warn-comma-operator.cpp
===================================================================
--- test/SemaCXX/warn-comma-operator.cpp
+++ test/SemaCXX/warn-comma-operator.cpp
@@ -276,3 +276,13 @@
   // CHECK: fix-it:{{.*}}:{[[@LINE-7]]:33-[[@LINE-7]]:33}:"static_cast<void>("
   // CHECK: fix-it:{{.*}}:{[[@LINE-8]]:46-[[@LINE-8]]:46}:")"
 }
+
+void returnsVoid();
+
+void noWarningForVoidReturns(int x) {
+  returnsVoid(), x = 0;
+  returnsVoid(),
+      return_four(), // expected-warning {{possible misuse of comma operator 
here}} \
+                        expected-note{{cast expression to void}}
+      returnsVoid();
+}
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -10648,6 +10648,8 @@
       return true;
     }
   }
+  if (E->getType()->isVoidType())
+    return true;
 
   return false;
 }


Index: test/SemaCXX/warn-comma-operator.cpp
===================================================================
--- test/SemaCXX/warn-comma-operator.cpp
+++ test/SemaCXX/warn-comma-operator.cpp
@@ -276,3 +276,13 @@
   // CHECK: fix-it:{{.*}}:{[[@LINE-7]]:33-[[@LINE-7]]:33}:"static_cast<void>("
   // CHECK: fix-it:{{.*}}:{[[@LINE-8]]:46-[[@LINE-8]]:46}:")"
 }
+
+void returnsVoid();
+
+void noWarningForVoidReturns(int x) {
+  returnsVoid(), x = 0;
+  returnsVoid(),
+      return_four(), // expected-warning {{possible misuse of comma operator here}} \
+                        expected-note{{cast expression to void}}
+      returnsVoid();
+}
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -10648,6 +10648,8 @@
       return true;
     }
   }
+  if (E->getType()->isVoidType())
+    return true;
 
   return false;
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to