Commit acfadf06 by Paolo Carlini Committed by Paolo Carlini

typeck2.c (digest_init_r): Use EXPR_LOC_OR_LOC on init.

/cp
2016-06-14  Paolo Carlini  <paolo.carlini@oracle.com>

	* typeck2.c (digest_init_r): Use EXPR_LOC_OR_LOC on init.

/testsuite
2016-06-14  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/init/array46.C: New.

From-SVN: r237444
parent 4d568ab2
2016-06-14 Paolo Carlini <paolo.carlini@oracle.com>
* typeck2.c (digest_init_r): Use EXPR_LOC_OR_LOC on init.
2016-06-13 Paolo Carlini <paolo.carlini@oracle.com> 2016-06-13 Paolo Carlini <paolo.carlini@oracle.com>
* decl.c (grokdeclarator): Fix typo in pedwarn text. * decl.c (grokdeclarator): Fix typo in pedwarn text.
......
...@@ -1009,6 +1009,8 @@ digest_init_r (tree type, tree init, bool nested, int flags, ...@@ -1009,6 +1009,8 @@ digest_init_r (tree type, tree init, bool nested, int flags,
if (TREE_CODE (init) == NON_LVALUE_EXPR) if (TREE_CODE (init) == NON_LVALUE_EXPR)
init = TREE_OPERAND (init, 0); 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 /* Initialization of an array of chars from a string constant. The initializer
can be optionally enclosed in braces, but reshape_init has already removed can be optionally enclosed in braces, but reshape_init has already removed
them if they were present. */ them if they were present. */
...@@ -1017,7 +1019,7 @@ digest_init_r (tree type, tree init, bool nested, int flags, ...@@ -1017,7 +1019,7 @@ digest_init_r (tree type, tree init, bool nested, int flags,
if (nested && !TYPE_DOMAIN (type)) if (nested && !TYPE_DOMAIN (type))
{ {
/* C++ flexible array members have a null domain. */ /* 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"); "initialization of a flexible array member");
} }
...@@ -1033,7 +1035,7 @@ digest_init_r (tree type, tree init, bool nested, int flags, ...@@ -1033,7 +1035,7 @@ digest_init_r (tree type, tree init, bool nested, int flags,
if (char_type != char_type_node) if (char_type != char_type_node)
{ {
if (complain & tf_error) if (complain & tf_error)
error ("char-array initialized from wide string"); error_at (loc, "char-array initialized from wide string");
return error_mark_node; return error_mark_node;
} }
} }
...@@ -1042,13 +1044,14 @@ digest_init_r (tree type, tree init, bool nested, int flags, ...@@ -1042,13 +1044,14 @@ digest_init_r (tree type, tree init, bool nested, int flags,
if (char_type == char_type_node) if (char_type == char_type_node)
{ {
if (complain & tf_error) 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; return error_mark_node;
} }
else if (char_type != typ1) else if (char_type != typ1)
{ {
if (complain & tf_error) if (complain & tf_error)
error ("int-array initialized from incompatible " error_at (loc, "int-array initialized from incompatible "
"wide string"); "wide string");
return error_mark_node; return error_mark_node;
} }
...@@ -1069,7 +1072,7 @@ digest_init_r (tree type, tree init, bool nested, int flags, ...@@ -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 counted in the length of the constant, but in C++ this would
be invalid. */ be invalid. */
if (size < TREE_STRING_LENGTH (init)) if (size < TREE_STRING_LENGTH (init))
permerror (input_location, "initializer-string for array " permerror (loc, "initializer-string for array "
"of chars is too long"); "of chars is too long");
} }
return init; return init;
...@@ -1122,7 +1125,7 @@ digest_init_r (tree type, tree init, bool nested, int flags, ...@@ -1122,7 +1125,7 @@ digest_init_r (tree type, tree init, bool nested, int flags,
if (COMPOUND_LITERAL_P (init) && TREE_CODE (type) == ARRAY_TYPE) if (COMPOUND_LITERAL_P (init) && TREE_CODE (type) == ARRAY_TYPE)
{ {
if (complain & tf_error) if (complain & tf_error)
error ("cannot initialize aggregate of type %qT with " error_at (loc, "cannot initialize aggregate of type %qT with "
"a compound literal", type); "a compound literal", type);
return error_mark_node; return error_mark_node;
...@@ -1140,7 +1143,7 @@ digest_init_r (tree type, tree init, bool nested, int flags, ...@@ -1140,7 +1143,7 @@ digest_init_r (tree type, tree init, bool nested, int flags,
return init; return init;
if (complain & tf_error) if (complain & tf_error)
error ("array must be initialized with a brace-enclosed" error_at (loc, "array must be initialized with a brace-enclosed"
" initializer"); " initializer");
return error_mark_node; return error_mark_node;
} }
......
2016-06-14 Paolo Carlini <paolo.carlini@oracle.com>
* g++.dg/init/array46.C: New.
2016-06-14 Uros Bizjak <ubizjak@gmail.com> 2016-06-14 Uros Bizjak <ubizjak@gmail.com>
* gcc.target/i386/float128-3.c: New test. * gcc.target/i386/float128-3.c: New test.
......
int foo();
int a[] = foo(); // { dg-error "14:initializer fails to determine size" }
// { dg-error "14:array must be initialized" "" { target *-*-* } 2 }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment