This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: fix PR 28687
- From: Benjamin Smedberg <benjamin at smedbergs dot us>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 11 Aug 2006 10:57:00 -0400
- Subject: C++ PATCH: fix PR 28687
Previously the construct dynamic_cast<void*> worked even when RTTI was
disabled, and was useful in Mozilla logging code. PR10891 changed this
behavior so that dynamic_cast is forbidden unconditionally when -fno-rtti is
used. This patch adds back support for dynamic casts that don't require RTTI
information and documents the limitations of dynamic_cast.
This fixes the Mozilla build against GCC trunk:
https://bugzilla.mozilla.org/show_bug.cgi?id=327189
--BDS
2006-08-11 Benjamin Smedberg <benjamin@smedbergs.us>
PR c++/28687
* doc/invoke.texi (-no-rtti): specifically document
dynamic_cast<void*>
cp/
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
testsuite/
2006-08-11 Benjamin Smedberg <benjamin@smedbergs.us>
PR c++/28687
* g++.dg/rtti/no-rtti-voidptr.C: new
Index: cp/rtti.c
===================================================================
--- cp/rtti.c (revision 116044)
+++ cp/rtti.c (working copy)
@@ -619,6 +619,13 @@ build_dynamic_cast_1 (tree type, tree ex
}
}
+ /* 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: testsuite/g++.dg/rtti/no-rtti-voidptr.C
===================================================================
--- testsuite/g++.dg/rtti/no-rtti-voidptr.C (revision 0)
+++ testsuite/g++.dg/rtti/no-rtti-voidptr.C (revision 0)
@@ -0,0 +1,21 @@
+// { do-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());
+}
Index: doc/invoke.texi
===================================================================
--- doc/invoke.texi (revision 116044)
+++ doc/invoke.texi (working copy)
@@ -1569,7 +1569,8 @@ functions for use by the C++ runtime typ
(@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 dynamic_cast operator can still be used for casts that do not
+require runtime type information, such as dynamic_cast<void*>.
@item -fstats
@opindex fstats