r345111 - [Sema] Fix -Wcomma in dependent context
Richard Trieu via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 23 19:07:41 PDT 2018
Author: rtrieu
Date: Tue Oct 23 19:07:41 2018
New Revision: 345111
URL: http://llvm.org/viewvc/llvm-project?rev=345111&view=rev
Log:
[Sema] Fix -Wcomma in dependent context
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
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaCXX/warn-comma-operator.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=345111&r1=345110&r2=345111&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Oct 23 19:07:41 2018
@@ -11280,6 +11280,12 @@ static bool IgnoreCommaOperand(const Exp
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;
Modified: cfe/trunk/test/SemaCXX/warn-comma-operator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-comma-operator.cpp?rev=345111&r1=345110&r2=345111&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-comma-operator.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-comma-operator.cpp Tue Oct 23 19:07:41 2018
@@ -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;
+}
More information about the cfe-commits
mailing list