re PR c++/28687 (dynamic_cast<void*> disallowed too rigorously with -fno-rtti)
authorBenjamin Smedberg <benjamin@smedbergs.us>
Wed, 23 Aug 2006 14:04:24 +0000 (14:04 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 23 Aug 2006 14:04:24 +0000 (10:04 -0400)
        PR c++/28687
        * rtti.c (build_dynamic_cast, build_dynamic_cast_1):
        Move -fno-rtti check to be more specific.

From-SVN: r116350

gcc/cp/ChangeLog
gcc/cp/rtti.c
gcc/doc/invoke.texi
gcc/testsuite/g++.dg/rtti/no-rtti-voidptr.C [new file with mode: 0644]

index ff60084b83c904dcdc86b30b887a852e1a661cc1..e2bc2dbb525df559f280bc19467f13c43589858e 100644 (file)
@@ -1,3 +1,9 @@
+2006-08-11   Benjamin Smedberg <benjamin@smedbergs.us>
+
+       PR c++/28687
+       * rtti.c (build_dynamic_cast, build_dynamic_cast_1):
+       Move -fno-rtti check to be more specific.
+
 2006-08-22  Jason Merrill  <jason@redhat.com>
 
        PR c++/23372
index 18beb7906f972e7fcd87fbaff040e5f78fc34055..b4cede48b06929fbeb09e84cd08c08d147f5b6ed 100644 (file)
@@ -619,6 +619,13 @@ build_dynamic_cast_1 (tree type, tree expr)
                }
            }
 
+         /* Use of dynamic_cast when -fno-rtti is prohibited.  */
+         if (!flag_rtti)
+           {
+             error ("%<dynamic_cast%> not permitted with -fno-rtti");
+             return error_mark_node;
+           }
+
          target_type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
          static_type = TYPE_MAIN_VARIANT (TREE_TYPE (exprtype));
          td2 = get_tinfo_decl (target_type);
@@ -704,13 +711,6 @@ build_dynamic_cast (tree type, tree expr)
   if (type == error_mark_node || expr == error_mark_node)
     return error_mark_node;
 
-  /* Use of dynamic_cast when -fno-rtti is prohibited.  */
-  if (!flag_rtti)
-    {
-      error ("%<dynamic_cast%> not permitted with -fno-rtti");
-      return error_mark_node;
-    }
-
   if (processing_template_decl)
     {
       expr = build_min (DYNAMIC_CAST_EXPR, type, expr);
index c9b25f754db954e3736e27916af26928114cebac..d7f0826fca4f44736c98011334c7ede1551fe510 100644 (file)
@@ -1569,7 +1569,9 @@ functions for use by the C++ runtime type identification features
 (@samp{dynamic_cast} and @samp{typeid}).  If you don't use those parts
 of the language, you can save some space by using this flag.  Note that
 exception handling uses the same information, but it will generate it as
-needed.
+needed. The @samp{dynamic_cast} operator can still be used for casts that
+do not require runtime type information, i.e. casts to @code{void *} or to
+unambiguous base classes.
 
 @item -fstats
 @opindex fstats
diff --git a/gcc/testsuite/g++.dg/rtti/no-rtti-voidptr.C b/gcc/testsuite/g++.dg/rtti/no-rtti-voidptr.C
new file mode 100644 (file)
index 0000000..2b3915d
--- /dev/null
@@ -0,0 +1,21 @@
+// { dg-do compile }
+// { dg-options "-fno-rtti" }
+
+// PR C++/28687
+
+struct A {
+  virtual ~A() { }
+};
+
+struct B : A {
+};
+
+A* f()
+{
+  return new B();
+}
+
+int main()
+{
+  void* b = dynamic_cast<void*>(f());
+}