From 2efc721885206a44fc19814a7b1ef3d83ba3d2ab Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Wed, 9 Dec 2015 16:59:26 +0000 Subject: [PATCH] re PR c++/60218 ([c++11] ICE using __bases for broken class hierarchy) /cp 2015-12-09 Paolo Carlini PR c++/60218 * semantics.c (calculate_bases_helper): Don't call dfs_walk_all when TYPE_BINFO (type) is null. (calculate_bases): Handle gracefully a null vector->length (). /testsuite 2015-12-09 Paolo Carlini PR c++/60218 * g++.dg/ext/bases2.C: New. From-SVN: r231460 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/semantics.c | 20 +++++++++++++------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/ext/bases2.C | 14 ++++++++++++++ 4 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/bases2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ac41ca655c5..e8bcba51162 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2015-12-09 Paolo Carlini + + PR c++/60218 + * semantics.c (calculate_bases_helper): Don't call dfs_walk_all + when TYPE_BINFO (type) is null. + (calculate_bases): Handle gracefully a null vector->length (). + 2015-12-08 Martin Sebor PR c++/68711 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 80d1b10ddad..b8f4e8f7ce7 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3851,8 +3851,9 @@ calculate_bases_helper (tree type) vec *vector = make_tree_vector(); /* Now add non-virtual base classes in order of construction */ - dfs_walk_all (TYPE_BINFO (type), - dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector); + if (TYPE_BINFO (type)) + dfs_walk_all (TYPE_BINFO (type), + dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector); return vector; } @@ -3886,13 +3887,18 @@ calculate_bases (tree type) vec_safe_splice (vector, nonvbases); release_tree_vector (nonvbases); - /* Last element is entire class, so don't copy */ - bases_vec = make_tree_vec (vector->length () - 1); - - for (i = 0; i < vector->length () - 1; ++i) + /* Note that during error recovery vector->length can even be zero. */ + if (vector->length () > 1) { - TREE_VEC_ELT (bases_vec, i) = (*vector)[i]; + /* Last element is entire class, so don't copy */ + bases_vec = make_tree_vec (vector->length() - 1); + + for (i = 0; i < vector->length () - 1; ++i) + TREE_VEC_ELT (bases_vec, i) = (*vector)[i]; } + else + bases_vec = make_tree_vec (0); + release_tree_vector (vector); return bases_vec; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d545bcbeacd..20f62afa684 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-12-09 Paolo Carlini + + PR c++/60218 + * g++.dg/ext/bases2.C: New. + 2015-12-09 Uros Bizjak * gcc.target/i386/sse4_1-roundps-1.c: Remove ASM_SUFFIX define. diff --git a/gcc/testsuite/g++.dg/ext/bases2.C b/gcc/testsuite/g++.dg/ext/bases2.C new file mode 100644 index 00000000000..a8806dde839 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/bases2.C @@ -0,0 +1,14 @@ +// PR c++/60218 +// { dg-do compile { target c++11 } } + +template struct A {}; + +template struct B +{ + typedef A<__bases(T)...> C; +}; + +struct X {}; +struct Y : X* {}; // { dg-error "expected" } + +B b; -- 2.30.2