r191340 - Allow dynamic_cast to void* even with -fno-rtti.

Eli Friedman eli.friedman at gmail.com
Tue Sep 24 16:21:41 PDT 2013


Author: efriedma
Date: Tue Sep 24 18:21:41 2013
New Revision: 191340

URL: http://llvm.org/viewvc/llvm-project?rev=191340&view=rev
Log:
Allow dynamic_cast to void* even with -fno-rtti.

PR17346.

Modified:
    cfe/trunk/lib/Sema/SemaCast.cpp
    cfe/trunk/test/SemaCXX/no-rtti.cpp

Modified: cfe/trunk/lib/Sema/SemaCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=191340&r1=191339&r2=191340&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCast.cpp Tue Sep 24 18:21:41 2013
@@ -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;

Modified: cfe/trunk/test/SemaCXX/no-rtti.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/no-rtti.cpp?rev=191340&r1=191339&r2=191340&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/no-rtti.cpp (original)
+++ cfe/trunk/test/SemaCXX/no-rtti.cpp Tue Sep 24 18:21:41 2013
@@ -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);
+}





More information about the cfe-commits mailing list