diff options
-rw-r--r-- | gcc/cp/call.cc | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/tree-ssa/initlist-opt2.C | 31 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/tree-ssa/initlist-opt3.C | 21 |
3 files changed, 54 insertions, 1 deletions
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index c25df17..bd174b8 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -4285,7 +4285,8 @@ maybe_init_list_as_array (tree elttype, tree init) static tree maybe_init_list_as_range (tree fn, tree expr) { - if (BRACE_ENCLOSED_INITIALIZER_P (expr) + if (!processing_template_decl + && BRACE_ENCLOSED_INITIALIZER_P (expr) && is_list_ctor (fn) && decl_in_std_namespace_p (fn)) { diff --git a/gcc/testsuite/g++.dg/tree-ssa/initlist-opt2.C b/gcc/testsuite/g++.dg/tree-ssa/initlist-opt2.C new file mode 100644 index 0000000..c20713a --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/initlist-opt2.C @@ -0,0 +1,31 @@ +// PR c++/105838 +// { dg-additional-options -fdump-tree-gimple } +// { dg-do compile { target c++11 } } + +// Test that we do range-initialization from const char *. +// { dg-final { scan-tree-dump {_M_range_initialize<const char\* const\*>} "gimple" } } + +#include <string> +#include <vector> + +void g (const void *); + +template <int N> +void f (const char *p) +{ + std::vector<std::string> lst = { + "aahing", "aaliis", "aarrgh", "abacas", "abacus", "abakas", "abamps", "abands", "abased", "abaser", "abases", "abasia", + "abated", "abater", "abates", "abatis", "abator", "abattu", "abayas", "abbacy", "abbess", "abbeys", "abbots", "abcees", + "abdabs", "abduce", "abduct", "abears", "abeigh", "abeles", "abelia", "abends", "abhors", "abided", "abider", "abides", + "abject", "abjure", "ablate", "ablaut", "ablaze", "ablest", "ablets", "abling", "ablins", "abloom", "ablush", "abmhos", + "aboard", "aboded", "abodes", "abohms", "abolla", "abomas", "aboral", "abords", "aborne", "aborts", "abound", "abouts", + "aboves", "abrade", "abraid", "abrash", "abrays", "abrazo", "abrege", "abrins", "abroad", "abrupt", "abseil", "absent", + }; + + g(&lst); +} + +void h (const char *p) +{ + f<0> (p); +} diff --git a/gcc/testsuite/g++.dg/tree-ssa/initlist-opt3.C b/gcc/testsuite/g++.dg/tree-ssa/initlist-opt3.C new file mode 100644 index 0000000..c750b99 --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/initlist-opt3.C @@ -0,0 +1,21 @@ +// PR c++/108266 +// { dg-do compile { target c++11 } } + +#include <initializer_list> +#include <vector> + +struct S { S (const char *); }; +void bar (std::vector<S>); + +template <int N> +void +foo () +{ + bar ({"", ""}); +} + +void +baz () +{ + foo<0> (); +} |