forked from OSchip/llvm-project
[Diagnostics] Improve some error messages related to bad use of dynamic_cast
This commit is contained in:
parent
0bab0538d8
commit
55507110b9
|
@ -6568,10 +6568,10 @@ def err_downcast_from_inaccessible_base : Error<
|
|||
def err_upcast_to_inaccessible_base : Error<
|
||||
"cannot cast %0 to its %select{private|protected}2 base class %1">;
|
||||
def err_bad_dynamic_cast_not_ref_or_ptr : Error<
|
||||
"%0 is not a reference or pointer">;
|
||||
def err_bad_dynamic_cast_not_class : Error<"%0 is not a class">;
|
||||
"invalid target type %0 for dynamic_cast; target type must be a reference or pointer type to a defined class">;
|
||||
def err_bad_dynamic_cast_not_class : Error<"%0 is not a class type">;
|
||||
def err_bad_dynamic_cast_incomplete : Error<"%0 is an incomplete type">;
|
||||
def err_bad_dynamic_cast_not_ptr : Error<"%0 is not a pointer">;
|
||||
def err_bad_dynamic_cast_not_ptr : Error<"cannot use dynamic_cast to convert from %0 to %1">;
|
||||
def err_bad_dynamic_cast_not_polymorphic : Error<"%0 is not polymorphic">;
|
||||
|
||||
// Other C++ expressions
|
||||
|
|
|
@ -763,7 +763,7 @@ void CastOperation::CheckDynamicCast() {
|
|||
SrcPointee = SrcPointer->getPointeeType();
|
||||
} else {
|
||||
Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_ptr)
|
||||
<< OrigSrcType << SrcExpr.get()->getSourceRange();
|
||||
<< OrigSrcType << this->DestType << SrcExpr.get()->getSourceRange();
|
||||
SrcExpr = ExprError();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -22,17 +22,17 @@ struct PolyDerived : Poly
|
|||
void basic_bad()
|
||||
{
|
||||
// ptr -> nonptr
|
||||
(void)dynamic_cast<A>((A*)0); // expected-error {{'A' is not a reference or pointer}}
|
||||
(void)dynamic_cast<A>((A*)0); // expected-error {{invalid target type 'A' for dynamic_cast; target type must be a reference or pointer type to a defined class}}
|
||||
// nonptr -> ptr
|
||||
(void)dynamic_cast<A*>(0); // expected-error {{'int' is not a pointer}}
|
||||
(void)dynamic_cast<A*>(0); // expected-error {{cannot use dynamic_cast to convert from 'int' to 'A *'}}
|
||||
// ptr -> noncls
|
||||
(void)dynamic_cast<int*>((A*)0); // expected-error {{'int' is not a class}}
|
||||
(void)dynamic_cast<int*>((A*)0); // expected-error {{'int' is not a class type}}
|
||||
// noncls -> ptr
|
||||
(void)dynamic_cast<A*>((int*)0); // expected-error {{'int' is not a class}}
|
||||
(void)dynamic_cast<A*>((int*)0); // expected-error {{'int' is not a class type}}
|
||||
// ref -> noncls
|
||||
(void)dynamic_cast<int&>(*((A*)0)); // expected-error {{'int' is not a class}}
|
||||
(void)dynamic_cast<int&>(*((A*)0)); // expected-error {{'int' is not a class type}}
|
||||
// noncls -> ref
|
||||
(void)dynamic_cast<A&>(*((int*)0)); // expected-error {{'int' is not a class}}
|
||||
(void)dynamic_cast<A&>(*((int*)0)); // expected-error {{'int' is not a class type}}
|
||||
// ptr -> incomplete
|
||||
(void)dynamic_cast<Incomplete*>((A*)0); // expected-error {{'Incomplete' is an incomplete type}}
|
||||
// incomplete -> ptr
|
||||
|
|
|
@ -57,7 +57,7 @@ template struct StaticCast0<int, A>; // expected-note{{instantiation}}
|
|||
template<typename T, typename U>
|
||||
struct DynamicCast0 {
|
||||
void f(T t) {
|
||||
(void)dynamic_cast<U>(t); // expected-error{{not a reference or pointer}}
|
||||
(void)dynamic_cast<U>(t); // expected-error{{invalid target type 'A' for dynamic_cast; target type must be a reference or pointer type to a defined class}}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue