From: Richard Trieu Date: Wed, 24 Oct 2018 02:07:41 +0000 (+0000) Subject: [Sema] Fix -Wcomma in dependent context X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6e5e0556a753b7ab4e4e59e0c48474b2c7e5b91e;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@345111 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 2cee761da3..98025ca27c 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -11280,6 +11280,12 @@ static bool IgnoreCommaOperand(const Expr *E) { if (CE->getCastKind() == CK_ToVoid) { return true; } + + // static_cast 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; diff --git a/test/SemaCXX/warn-comma-operator.cpp b/test/SemaCXX/warn-comma-operator.cpp index 3192f688f1..75ef4521cb 100644 --- a/test/SemaCXX/warn-comma-operator.cpp +++ b/test/SemaCXX/warn-comma-operator.cpp @@ -276,3 +276,13 @@ void test14() { // CHECK: fix-it:{{.*}}:{[[@LINE-7]]:33-[[@LINE-7]]:33}:"static_cast(" // CHECK: fix-it:{{.*}}:{[[@LINE-8]]:46-[[@LINE-8]]:46}:")" } + +// PR39375 - test cast to void to silence warnings +template +void test15() { + (void)42, 0; + static_cast(42), 0; + + (void)T{}, 0; + static_cast(T{}), 0; +}