aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2016-06-14 14:15:53 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2016-06-14 14:15:53 +0000
commitacfadf066def1f73e4cb0a7bc4cd368165302fa2 (patch)
tree27b84d9ad88b675b4c1274c0ef0d641a0728a6b0
parent4d568ab255e88918debfd75f010dfefa8f8d8738 (diff)
downloadgcc-acfadf066def1f73e4cb0a7bc4cd368165302fa2.zip
gcc-acfadf066def1f73e4cb0a7bc4cd368165302fa2.tar.gz
gcc-acfadf066def1f73e4cb0a7bc4cd368165302fa2.tar.bz2
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
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/typeck2.c23
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/g++.dg/init/array46.C3
4 files changed, 24 insertions, 10 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 2b17452..64acdc8 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,7 @@
+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>
* decl.c (grokdeclarator): Fix typo in pedwarn text.
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 835a44f..65d91c9 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 d2bad98..3addc24 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2016-06-14 Paolo Carlini <paolo.carlini@oracle.com>
+
+ * g++.dg/init/array46.C: New.
+
2016-06-14 Uros Bizjak <ubizjak@gmail.com>
* 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 0000000..34fc266
--- /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 }