Sema: Check value dependent casts when possible

We know that const_cast<char *>((void)Something) is ill-formed, even if
'Something' is dependent because you can't cast from void to a pointer
type.

This fixes PR21845.

llvm-svn: 224299
This commit is contained in:
David Majnemer 2014-12-16 00:46:30 +00:00
parent b58f003e86
commit e64941fa60
2 changed files with 5 additions and 4 deletions

View File

@ -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());

View File

@ -64,3 +64,6 @@ short *bad_const_cast_test(char const *volatile *const volatile *var)
(void)const_cast<int&&>(0); // expected-error {{const_cast from rvalue to reference type 'int &&'}} expected-warning {{C++11}}
return **var3;
}
template <typename T>
char *PR21845() { return const_cast<char *>((void)T::x); } // expected-error {{const_cast from 'void' to 'char *' is not allowed}}