From acfadf066def1f73e4cb0a7bc4cd368165302fa2 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Tue, 14 Jun 2016 14:15:53 +0000 Subject: [PATCH] typeck2.c (digest_init_r): Use EXPR_LOC_OR_LOC on init. /cp 2016-06-14 Paolo Carlini * typeck2.c (digest_init_r): Use EXPR_LOC_OR_LOC on init. /testsuite 2016-06-14 Paolo Carlini * g++.dg/init/array46.C: New. From-SVN: r237444 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/typeck2.c | 23 +++++++++++++---------- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/init/array46.C | 3 +++ 4 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/g++.dg/init/array46.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2b17452d812..64acdc81458 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,7 @@ +2016-06-14 Paolo Carlini + + * typeck2.c (digest_init_r): Use EXPR_LOC_OR_LOC on init. + 2016-06-13 Paolo Carlini * decl.c (grokdeclarator): Fix typo in pedwarn text. diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 835a44f1cf6..65d91c97784 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -1009,6 +1009,8 @@ digest_init_r (tree type, tree init, bool nested, int flags, if (TREE_CODE (init) == NON_LVALUE_EXPR) init = TREE_OPERAND (init, 0); + location_t loc = EXPR_LOC_OR_LOC (init, input_location); + /* Initialization of an array of chars from a string constant. The initializer can be optionally enclosed in braces, but reshape_init has already removed them if they were present. */ @@ -1017,7 +1019,7 @@ digest_init_r (tree type, tree init, bool nested, int flags, if (nested && !TYPE_DOMAIN (type)) { /* C++ flexible array members have a null domain. */ - pedwarn (EXPR_LOC_OR_LOC (init, input_location), OPT_Wpedantic, + pedwarn (loc, OPT_Wpedantic, "initialization of a flexible array member"); } @@ -1033,7 +1035,7 @@ digest_init_r (tree type, tree init, bool nested, int flags, if (char_type != char_type_node) { if (complain & tf_error) - error ("char-array initialized from wide string"); + error_at (loc, "char-array initialized from wide string"); return error_mark_node; } } @@ -1042,14 +1044,15 @@ digest_init_r (tree type, tree init, bool nested, int flags, if (char_type == char_type_node) { if (complain & tf_error) - error ("int-array initialized from non-wide string"); + error_at (loc, + "int-array initialized from non-wide string"); return error_mark_node; } else if (char_type != typ1) { if (complain & tf_error) - error ("int-array initialized from incompatible " - "wide string"); + error_at (loc, "int-array initialized from incompatible " + "wide string"); return error_mark_node; } } @@ -1069,7 +1072,7 @@ digest_init_r (tree type, tree init, bool nested, int flags, counted in the length of the constant, but in C++ this would be invalid. */ if (size < TREE_STRING_LENGTH (init)) - permerror (input_location, "initializer-string for array " + permerror (loc, "initializer-string for array " "of chars is too long"); } return init; @@ -1122,8 +1125,8 @@ digest_init_r (tree type, tree init, bool nested, int flags, if (COMPOUND_LITERAL_P (init) && TREE_CODE (type) == ARRAY_TYPE) { if (complain & tf_error) - error ("cannot initialize aggregate of type %qT with " - "a compound literal", type); + error_at (loc, "cannot initialize aggregate of type %qT with " + "a compound literal", type); return error_mark_node; } @@ -1140,8 +1143,8 @@ digest_init_r (tree type, tree init, bool nested, int flags, return init; if (complain & tf_error) - error ("array must be initialized with a brace-enclosed" - " initializer"); + error_at (loc, "array must be initialized with a brace-enclosed" + " initializer"); return error_mark_node; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d2bad9859c4..3addc24998f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-06-14 Paolo Carlini + + * g++.dg/init/array46.C: New. + 2016-06-14 Uros Bizjak * gcc.target/i386/float128-3.c: New test. diff --git a/gcc/testsuite/g++.dg/init/array46.C b/gcc/testsuite/g++.dg/init/array46.C new file mode 100644 index 00000000000..34fc2665756 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/array46.C @@ -0,0 +1,3 @@ +int foo(); +int a[] = foo(); // { dg-error "14:initializer fails to determine size" } +// { dg-error "14:array must be initialized" "" { target *-*-* } 2 } -- 2.30.2