From: David Majnemer Date: Tue, 16 Dec 2014 00:46:30 +0000 (+0000) Subject: Sema: Check value dependent casts when possible X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=49a14e5fc88765c7280fd94c319341ee36f6ae78;p=clang Sema: Check value dependent casts when possible We know that const_cast((void)Something) is ill-formed, even if 'Something' is dependent because you can't cast from void to a pointer type. This fixes PR21845. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224299 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaCast.cpp b/lib/Sema/SemaCast.cpp index d38db87fa5..a4c2d9b51c 100644 --- a/lib/Sema/SemaCast.cpp +++ b/lib/Sema/SemaCast.cpp @@ -240,10 +240,8 @@ Sema::BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, QualType DestType = DestTInfo->getType(); // If the type is dependent, we won't do the semantic analysis now. - // FIXME: should we check this in a more fine-grained manner? - bool TypeDependent = DestType->isDependentType() || - Ex.get()->isTypeDependent() || - Ex.get()->isValueDependent(); + bool TypeDependent = + DestType->isDependentType() || Ex.get()->isTypeDependent(); CastOperation Op(*this, DestType, E); Op.OpRange = SourceRange(OpLoc, Parens.getEnd()); diff --git a/test/SemaCXX/const-cast.cpp b/test/SemaCXX/const-cast.cpp index cb9937c50d..330e18661b 100644 --- a/test/SemaCXX/const-cast.cpp +++ b/test/SemaCXX/const-cast.cpp @@ -64,3 +64,6 @@ short *bad_const_cast_test(char const *volatile *const volatile *var) (void)const_cast(0); // expected-error {{const_cast from rvalue to reference type 'int &&'}} expected-warning {{C++11}} return **var3; } + +template +char *PR21845() { return const_cast((void)T::x); } // expected-error {{const_cast from 'void' to 'char *' is not allowed}}