mirror of
https://github.com/llvm/llvm-project.git
synced 2025-05-01 10:36:07 +00:00
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:
parent
b58f003e86
commit
e64941fa60
@ -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());
|
||||
|
@ -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}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user