]> granicus.if.org Git - clang/commitdiff
[Sema] Fix -Wcomma in dependent context
authorRichard Trieu <rtrieu@google.com>
Wed, 24 Oct 2018 02:07:41 +0000 (02:07 +0000)
committerRichard Trieu <rtrieu@google.com>
Wed, 24 Oct 2018 02:07:41 +0000 (02:07 +0000)
When there is a dependent type inside a cast, the CastKind becomes CK_Dependent
instead of CK_ToVoid.  This fix will check that there is a dependent cast,
the original type is dependent, and the target type is void to ignore the cast.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@345111 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 2cee761da3c509c4beeb62c77e1bd12b1dff86b3..98025ca27c6e5b155c332b9f97e62747cc0d4ae0 100644 (file)
@@ -11280,6 +11280,12 @@ static bool IgnoreCommaOperand(const Expr *E) {
     if (CE->getCastKind() == CK_ToVoid) {
       return true;
     }
+
+    // static_cast<void> on a dependent type will not show up as CK_ToVoid.
+    if (CE->getCastKind() == CK_Dependent && E->getType()->isVoidType() &&
+        CE->getSubExpr()->getType()->isDependentType()) {
+      return true;
+    }
   }
 
   return false;
index 3192f688f1ba0f3b0a9592bdddb9f9ff1c51225b..75ef4521cb9b2a44541fb762ddf51a2a0e95f86a 100644 (file)
@@ -276,3 +276,13 @@ void test14() {
   // CHECK: fix-it:{{.*}}:{[[@LINE-7]]:33-[[@LINE-7]]:33}:"static_cast<void>("
   // CHECK: fix-it:{{.*}}:{[[@LINE-8]]:46-[[@LINE-8]]:46}:")"
 }
+
+// PR39375 - test cast to void to silence warnings
+template <typename T>
+void test15() {
+  (void)42, 0;
+  static_cast<void>(42), 0;
+
+  (void)T{}, 0;
+  static_cast<void>(T{}), 0;
+}