[PATCH] D34810: [Sema] -Wcomma should not warn for expression that return void

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 29 04:24:27 PDT 2017


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;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34810.104619.patch
Type: text/x-patch
Size: 926 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170629/8358e963/attachment.bin>


More information about the cfe-commits mailing list