]> gcc.gnu.org Git - gcc.git/commitdiff
typeck2.c (digest_init_r): Use EXPR_LOC_OR_LOC on init.
authorPaolo Carlini <paolo.carlini@oracle.com>
Tue, 14 Jun 2016 14:15:53 +0000 (14:15 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 14 Jun 2016 14:15:53 +0000 (14:15 +0000)
/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

gcc/cp/ChangeLog
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/array46.C [new file with mode: 0644]

index 2b17452d8122a1ca2feb138d52bbe3104742c548..64acdc814580ae0ddea70ce902504db99755a4c5 100644 (file)
@@ -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.
index 835a44f1cf6188fe9d4d5ad11a89f4ef8cf4a61c..65d91c97784997f26351f3bb86ef33ae57b90ae9 100644 (file)
@@ -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;
        }
 
index d2bad9859c42562d1c66ed350df4ea7a4445f600..3addc24998ffc788d9fd28ee69702b355ba4a57a 100644 (file)
@@ -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 (file)
index 0000000..34fc266
--- /dev/null
@@ -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 }
This page took 0.074713 seconds and 5 git commands to generate.