This fixes c++/88741, a bogus error with using [] in a template. Starting with the "more location wrapper nodes" patch, cp_complete_array_type can now receive a V_C_E in a CONSTRUCTOR, instead of just {"test"}, so we need to strip any location wrappers as elsewhere for this code to work.
Bootstrapped/regtested on x86_64-linux, ok for trunk? 2019-01-07 Marek Polacek <pola...@redhat.com> PR c++/88741 - wrong error with initializer-string. * decl.c (cp_complete_array_type): Strip any location wrappers. * g++.dg/init/array50.C: New test. diff --git gcc/cp/decl.c gcc/cp/decl.c index 15bc4887a59..1fc7a1acf56 100644 --- gcc/cp/decl.c +++ gcc/cp/decl.c @@ -8433,6 +8433,7 @@ cp_complete_array_type (tree *ptype, tree initial_value, bool do_default) { vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initial_value); tree value = (*v)[0].value; + STRIP_ANY_LOCATION_WRAPPER (value); if (TREE_CODE (value) == STRING_CST && v->length () == 1) diff --git gcc/testsuite/g++.dg/init/array50.C gcc/testsuite/g++.dg/init/array50.C new file mode 100644 index 00000000000..a5c129d0eb5 --- /dev/null +++ gcc/testsuite/g++.dg/init/array50.C @@ -0,0 +1,12 @@ +// PR c++/88741 + +template <class T> +void foo() +{ + char row[] = {"test"}; +} + +void bar() +{ + foo<int>(); +}