]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/10891 (code using dynamic_cast causes segfaults when -fno-rtti is used)
authorGabriel Dos Reis <gdr@integrable-solutions.net>
Sun, 22 Jan 2006 17:32:30 +0000 (17:32 +0000)
committerGabriel Dos Reis <gdr@gcc.gnu.org>
Sun, 22 Jan 2006 17:32:30 +0000 (17:32 +0000)
2006-01-22  Gabriel Dos Reis  <gdr@integrable-solutions.net>

        PR c++/10891
        * rtti.c (build_dynamic_cast): Reject dynamic_cast use if
        -fno-rtti.

testsuite/
2006-01-22  Gabriel Dos Reis  <gdr@integrable-solutions.net>

        PR c++/10891
        * g++.dg/rtti/no-rtti.C: New.

From-SVN: r110092

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

index ea7355bcccecaba00376ab001a34b6aeef3a9724..a4ff093795d8ef155e5be268a1ec0b12e9a13861 100644 (file)
@@ -1,3 +1,9 @@
+2006-01-22  Gabriel Dos Reis  <gdr@integrable-solutions.net>
+
+       PR c++/10891
+       * rtti.c (build_dynamic_cast): Reject dynamic_cast use if
+       -fno-rtti. 
+
 2006-01-21  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/25895
index 8a3582de3de1f681f151d10b6f35d6f639200db5..e8cb52b9c55c8c02490b35ad776c41204034e483 100644 (file)
@@ -699,6 +699,14 @@ 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 a disaster waiting to happen.
+     See PR C++/10891.  Reject.  */
+  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 07aa699ca0c60f9ca2163df6e383518603a24610..57945e8ad34c10a080bbc645a51b158df074d9bb 100644 (file)
@@ -1,3 +1,8 @@
+2006-01-22  Gabriel Dos Reis  <gdr@integrable-solutions.net>
+
+       PR c++/10891
+       * g++.dg/rtti/no-rtti.C: New.
+
 2006-01-21  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/25895
diff --git a/gcc/testsuite/g++.dg/rtti/no-rtti.C b/gcc/testsuite/g++.dg/rtti/no-rtti.C
new file mode 100644 (file)
index 0000000..ca9cb72
--- /dev/null
@@ -0,0 +1,18 @@
+// { dg-do compile }
+// { dg-options "-fno-rtti" }
+
+// PR C++/10891
+
+struct A {
+   virtual ~A() { }
+};
+
+struct B : A {
+};
+
+A* f();
+
+int main()
+{
+   B* b = dynamic_cast<B*>(f()); // { dg-error "error: " }
+}