Skip to content

Commit

Permalink
[Diagnostics] Improve some error messages related to bad use of dynam…
Browse files Browse the repository at this point in the history
…ic_cast
  • Loading branch information
davidbolvansky committed Nov 4, 2019
1 parent 0bab053 commit 5550711
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaCast.cpp
Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions clang/test/SemaCXX/dynamic-cast.cpp
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clang/test/SemaTemplate/instantiate-cast.cpp
Expand Up @@ -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}}
}
};

Expand Down

0 comments on commit 5550711

Please sign in to comment.