Skip to content

Commit

Permalink
Allow dynamic_cast to void* even with -fno-rtti.
Browse files Browse the repository at this point in the history
PR17346.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191340 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
eefriedman committed Sep 24, 2013
1 parent 2ae28e5 commit 01ae093
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/Sema/SemaCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,10 @@ void CastOperation::CheckDynamicCast() {
Self.MarkVTableUsed(OpRange.getBegin(),
cast<CXXRecordDecl>(SrcRecord->getDecl()));

// dynamic_cast is not available with fno-rtti
if (!Self.getLangOpts().RTTI) {
// dynamic_cast is not available with -fno-rtti.
// As an exception, dynamic_cast to void* is available because it doesn't
// use RTTI.
if (!Self.getLangOpts().RTTI && !DestPointee->isVoidType()) {
Self.Diag(OpRange.getBegin(), diag::err_no_dynamic_cast_with_fno_rtti);
SrcExpr = ExprError();
return;
Expand Down
5 changes: 5 additions & 0 deletions test/SemaCXX/no-rtti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ struct B : public A {
bool isa_B(A *a) {
return dynamic_cast<B *>(a) != 0; // expected-error {{cannot use dynamic_cast with -fno-rtti}}
}

void* getMostDerived(A* a) {
// This cast does not use RTTI.
return dynamic_cast<void *>(a);
}

0 comments on commit 01ae093

Please sign in to comment.