This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 29318
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 12 Oct 2006 21:15:01 -0700
- Subject: C++ PATCH: PR 29318
- Reply-to: mark at codesourcery dot com
This patch fixes PR c++/29318. In this PR, we were crashing when
asked to provide a type_info object for a pointer to a VLA. We
already issued errors about trying to provide type_info for a VLA --
but not about other variably modified types. Since any variablying
modified type eventually requires generating a reference to a VLA, and
since the C++ ABI provides no way to have type_info for such a thing
(since it's not part of ISO C++), we should issue errors about all
variably modified types, as implemented by this patch.
Tested on x86_64-unknown-linux-gnu, applied on the mainline. I will
apply to 4.1 as soon as testing completes.
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713
2006-10-12 Mark Mitchell <mark@codesourcery.com>
PR c++/29318
* rtti.c (get_tinfo_decl): Refuse to create type info objects for
variably modified types.
2006-10-12 Mark Mitchell <mark@codesourcery.com>
PR c++/29318
* g++.dg/ext/vla4.C: New test.
Index: gcc/cp/rtti.c
===================================================================
--- gcc/cp/rtti.c (revision 117657)
+++ gcc/cp/rtti.c (working copy)
@@ -342,11 +342,10 @@ get_tinfo_decl (tree type)
tree name;
tree d;
- if (COMPLETE_TYPE_P (type)
- && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
+ if (variably_modified_type_p (type, /*fn=*/NULL_TREE))
{
error ("cannot create type information for type %qT because "
- "its size is variable",
+ "it involves types of variable size",
type);
return error_mark_node;
}
Index: gcc/testsuite/g++.dg/ext/vla4.C
===================================================================
--- gcc/testsuite/g++.dg/ext/vla4.C (revision 0)
+++ gcc/testsuite/g++.dg/ext/vla4.C (revision 0)
@@ -0,0 +1,21 @@
+// PR c++/29318
+// { dg-options "" }
+
+#include <typeinfo>
+
+void f(int i) {
+ try {
+ int a[i];
+ throw &a; // { dg-error "variable size" }
+ } catch (int (&)[i]) { // { dg-error "variable size" }
+ }
+}
+
+int main()
+{
+ int i = 5;
+ int va[i];
+ const std::type_info& info(typeid(&va)); // { dg-error "variable size" }
+
+ return 0;
+}