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