aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2006-08-23 14:04:24 +0000
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2006-08-23 14:04:24 +0000
commit614d94f2c71bee688b837f23b6ad3be57b70d16e (patch)
tree8db35c6e896f3c47a77d77c5ef83c8f54ece5934
parent97ee3d67a0503f2988f17db0cb0860cb38bc2cae (diff)
* rtti.c (build_dynamic_cast, build_dynamic_cast_1): Move -fno-rtti check to be more specific. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@116350 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/rtti.c14
-rw-r--r--gcc/doc/invoke.texi4
-rw-r--r--gcc/testsuite/g++.dg/rtti/no-rtti-voidptr.C21
4 files changed, 37 insertions, 8 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index ff60084b83c..e2bc2dbb525 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c
index 18beb7906f9..b4cede48b06 100644
--- a/gcc/cp/rtti.c
+++ b/gcc/cp/rtti.c
@@ -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);
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index c9b25f754db..d7f0826fca4 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -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
index 00000000000..2b3915d179c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/rtti/no-rtti-voidptr.C
@@ -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());
+}