From 774ae645c0c30c19a751b5c3713beef3aa5d8f28 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 16 Jan 2018 09:43:31 +0100 Subject: [PATCH] re PR c++/83825 (ICE on invalid C++ code with shadowed identifiers: in operator[], at vec.h:826) PR c++/83825 * name-lookup.c (member_vec_dedup): Return early if len is 0. (resort_type_member_vec, set_class_bindings, insert_late_enum_def_bindings): Use vec qsort method instead of calling qsort directly. * g++.dg/template/pr83825.C: New test. From-SVN: r256725 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/name-lookup.c | 12 ++++++------ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/template/pr83825.C | 13 +++++++++++++ 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/pr83825.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7e437f8547b..2371a54d004 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2018-01-16 Jakub Jelinek + + PR c++/83825 + * name-lookup.c (member_vec_dedup): Return early if len is 0. + (resort_type_member_vec, set_class_bindings, + insert_late_enum_def_bindings): Use vec qsort method instead of + calling qsort directly. + 2018-01-15 Martin Sebor PR c++/83588 diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index cddafab29fe..8d342939327 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -1520,8 +1520,7 @@ resort_type_member_vec (void *obj, void */*orig_obj*/, { resort_data.new_value = new_value; resort_data.cookie = cookie; - qsort (member_vec->address (), member_vec->length (), - sizeof (tree), resort_member_name_cmp); + member_vec->qsort (resort_member_name_cmp); } } @@ -1597,6 +1596,9 @@ member_vec_dedup (vec *member_vec) unsigned len = member_vec->length (); unsigned store = 0; + if (!len) + return; + tree current = (*member_vec)[0], name = OVL_NAME (current); tree next = NULL_TREE, next_name = NULL_TREE; for (unsigned jx, ix = 0; ix < len; @@ -1712,8 +1714,7 @@ set_class_bindings (tree klass, unsigned extra) if (member_vec) { CLASSTYPE_MEMBER_VEC (klass) = member_vec; - qsort (member_vec->address (), member_vec->length (), - sizeof (tree), member_name_cmp); + member_vec->qsort (member_name_cmp); member_vec_dedup (member_vec); } } @@ -1741,8 +1742,7 @@ insert_late_enum_def_bindings (tree klass, tree enumtype) else member_vec_append_class_fields (member_vec, klass); CLASSTYPE_MEMBER_VEC (klass) = member_vec; - qsort (member_vec->address (), member_vec->length (), - sizeof (tree), member_name_cmp); + member_vec->qsort (member_name_cmp); member_vec_dedup (member_vec); } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6b841401d41..2a44bb18080 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-01-16 Jakub Jelinek + + PR c++/83825 + * g++.dg/template/pr83825.C: New test. + 2018-01-16 Richard Biener * gcc.dg/graphite/pr83435.c: Restrict to target pthread. diff --git a/gcc/testsuite/g++.dg/template/pr83825.C b/gcc/testsuite/g++.dg/template/pr83825.C new file mode 100644 index 00000000000..ba3ff4dcee2 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/pr83825.C @@ -0,0 +1,13 @@ +// PR c++/83825 +// { dg-do compile } + +template +class A {}; // { dg-error "shadows template parameter" } + +template +class B +{ + void foo () { A a; } +}; + +template void B <0>::foo (); -- 2.30.2