This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] PR c++/51477 - ICE with invalid NSDMI
- From: Dodji Seketeli <dodji at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Jason Merrill <jason at redhat dot com>
- Date: Tue, 13 Dec 2011 22:24:16 +0100
- Subject: [PATCH] PR c++/51477 - ICE with invalid NSDMI
Hello,
In the example of this patch, during the implicit declaration of the
destructor, walk_field_subobs calls locate_fn_flags on the field
invalid field 'x', to locate its destructor. That function pokes the
BINFO of that field, which is NULL, and passes it along to
lookup_fnfields. And we ICE because of that NULL base type.
Just preventing lookup_member from crashing because of a NULL (or
otherwise invalid) base type fixes the issue.
Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk.
gcc/cp/
PR c++/51477
* search.c (lookup_member): Get out early on invalid base type.
gcc/testsuite/
PR c++/51477
* g++.dg/cpp0x/nsdmi6.C: New test.
---
gcc/cp/search.c | 4 +++-
gcc/testsuite/g++.dg/cpp0x/nsdmi6.C | 8 ++++++++
2 files changed, 11 insertions(+), 1 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp0x/nsdmi6.C
diff --git a/gcc/cp/search.c b/gcc/cp/search.c
index 3894c68..0ceb5bc 100644
--- a/gcc/cp/search.c
+++ b/gcc/cp/search.c
@@ -1171,7 +1171,9 @@ lookup_member (tree xbasetype, tree name, int protect, bool want_type,
const char *errstr = 0;
- if (name == error_mark_node)
+ if (name == error_mark_node
+ || xbasetype == NULL_TREE
+ || xbasetype == error_mark_node)
return NULL_TREE;
gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi6.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi6.C
new file mode 100644
index 0000000..bb455e7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi6.C
@@ -0,0 +1,8 @@
+// Origin PR c++/51477
+// { dg-options "-std=c++11" }
+
+struct A
+{
+ typedef int int T; // { dg-error "two or more data types in declaration" }
+ struct T x[1] = { 0 }; // { dg-error "invalid|forward" }
+};
--
1.7.6.4
--
Dodji