From: Paolo Carlini Date: Fri, 4 Apr 2014 20:11:47 +0000 (+0000) Subject: re PR c++/58207 (ICE in sort_constexpr_mem_initializers due to out of bounds vector... X-Git-Tag: upstream/12.2.0~63965 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9119c7fabaf186b2018292e6d92733c9e50237a1;p=platform%2Fupstream%2Fgcc.git re PR c++/58207 (ICE in sort_constexpr_mem_initializers due to out of bounds vector access) /cp 2014-04-04 Paolo Carlini PR c++/58207 * semantics.c (sort_constexpr_mem_initializers): Robustify loop. /testsuite 2014-04-04 Paolo Carlini PR c++/58207 * g++.dg/cpp0x/constexpr-ice15.C: New. From-SVN: r209128 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b3b9ccb..76f7aa9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2014-04-04 Paolo Carlini + + PR c++/58207 + * semantics.c (sort_constexpr_mem_initializers): Robustify loop. + 2014-04-04 Patrick Palka PR c++/44613 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 9269541..3619e27 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -7720,8 +7720,8 @@ sort_constexpr_mem_initializers (tree type, vec *v) { tree pri = CLASSTYPE_PRIMARY_BINFO (type); tree field_type; - constructor_elt elt; - int i; + unsigned i; + constructor_elt *ce; if (pri) field_type = BINFO_TYPE (pri); @@ -7732,14 +7732,14 @@ sort_constexpr_mem_initializers (tree type, vec *v) /* Find the element for the primary base or vptr and move it to the beginning of the vec. */ - vec &vref = *v; - for (i = 0; ; ++i) - if (TREE_TYPE (vref[i].index) == field_type) + for (i = 0; vec_safe_iterate (v, i, &ce); ++i) + if (TREE_TYPE (ce->index) == field_type) break; - if (i > 0) + if (i > 0 && i < vec_safe_length (v)) { - elt = vref[i]; + vec &vref = *v; + constructor_elt elt = vref[i]; for (; i > 0; --i) vref[i] = vref[i-1]; vref[0] = elt; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b073b7f..0cd68ca 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-04-04 Paolo Carlini + + PR c++/58207 + * g++.dg/cpp0x/constexpr-ice15.C: New. + 2014-04-04 Jan Hubicka PR ipa/59626 diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ice15.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ice15.C new file mode 100644 index 0000000..576fd41 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ice15.C @@ -0,0 +1,12 @@ +// PR c++/58207 +// { dg-do compile { target c++11 } } + +struct A +{ + virtual bool foo (); +}; + +struct B : public A +{ + constexpr B () : A (&::n) {} // { dg-error "declared" } +};