From 9cf2c541315d43f6c6a485f566910b1186ace749 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 24 Jun 2016 10:23:18 -0400
Subject: [PATCH 10/31] FIXME: C++ FE: better location for bad array sizes

---
 gcc/cp/decl.c | 51 +++++++++++++++++++++++++++++++--------------------
 1 file changed, 31 insertions(+), 20 deletions(-)

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index c86a131..f685a31 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -8738,6 +8738,8 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
   if (error_operand_p (size))
     return error_mark_node;
 
+  location_t size_loc = location_of (size);
+
   if (!type_dependent_expression_p (size))
     {
       tree type = TREE_TYPE (size);
@@ -8761,10 +8763,12 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
 		  if (!(complain & tf_error))
 		    return error_mark_node;
 		  if (name)
-		    error ("size of array %qD has non-integral type %qT",
-			   name, type);
+		    error_at (size_loc,
+			      "size of array %qD has non-integral type %qT",
+			      name, type);
 		  else
-		    error ("size of array has non-integral type %qT", type);
+		    error_at (size_loc,
+			      "size of array has non-integral type %qT", type);
 		  size = integer_one_node;
 		}
 	      if (size == error_mark_node)
@@ -8788,9 +8792,11 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
 	  if (!(complain & tf_error))
 	    return error_mark_node;
 	  if (name)
-	    error ("size of array %qD has non-integral type %qT", name, type);
+	    error_at (size_loc, "size of array %qD has non-integral type %qT",
+		      name, type);
 	  else
-	    error ("size of array has non-integral type %qT", type);
+	    error_at (size_loc, "size of array has non-integral type %qT",
+		      type);
 	  size = integer_one_node;
 	  type = TREE_TYPE (size);
 	}
@@ -8820,7 +8826,7 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
     {
       tree folded = cp_fully_fold (size);
       if (TREE_CODE (folded) == INTEGER_CST)
-	pedwarn (location_of (size), OPT_Wpedantic,
+	pedwarn (size_loc, OPT_Wpedantic,
 		 "size of array is not an integral constant-expression");
       /* Use the folded result for VLAs, too; it will have resolved
 	 SIZEOF_EXPR.  */
@@ -8840,9 +8846,9 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
 	  if (!(complain & tf_error))
 	    return error_mark_node;
 	  if (name)
-	    error ("size of array %qD is negative", name);
+	    error_at (size_loc, "size of array %qD is negative", name);
 	  else
-	    error ("size of array is negative");
+	    error_at (size_loc, "size of array is negative");
 	  size = integer_one_node;
 	}
       /* As an extension we allow zero-sized arrays.  */
@@ -8856,9 +8862,11 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
 	  else if (in_system_header_at (input_location))
 	    /* Allow them in system headers because glibc uses them.  */;
 	  else if (name)
-	    pedwarn (input_location, OPT_Wpedantic, "ISO C++ forbids zero-size array %qD", name);
+	    pedwarn (size_loc, OPT_Wpedantic,
+		     "ISO C++ forbids zero-size array %qD", name);
 	  else
-	    pedwarn (input_location, OPT_Wpedantic, "ISO C++ forbids zero-size array");
+	    pedwarn (size_loc, OPT_Wpedantic,
+		     "ISO C++ forbids zero-size array");
 	}
     }
   else if (TREE_CONSTANT (size)
@@ -8871,27 +8879,30 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
 	return error_mark_node;
       /* `(int) &fn' is not a valid array bound.  */
       if (name)
-	error ("size of array %qD is not an integral constant-expression",
-	       name);
+	error_at (size_loc,
+		  "size of array %qD is not an integral constant-expression",
+		  name);
       else
-	error ("size of array is not an integral constant-expression");
+	error_at (size_loc,
+		  "size of array is not an integral constant-expression");
       size = integer_one_node;
     }
   else if (pedantic && warn_vla != 0)
     {
       if (name)
-	pedwarn (input_location, OPT_Wvla, "ISO C++ forbids variable length array %qD", name);
+	pedwarn (size_loc, OPT_Wvla,
+		 "ISO C++ forbids variable length array %qD", name);
       else
-	pedwarn (input_location, OPT_Wvla, "ISO C++ forbids variable length array");
+	pedwarn (size_loc, OPT_Wvla, "ISO C++ forbids variable length array");
     }
   else if (warn_vla > 0)
     {
       if (name)
-	warning (OPT_Wvla, 
-                 "variable length array %qD is used", name);
+	warning_at (size_loc, OPT_Wvla,
+		    "variable length array %qD is used", name);
       else
-	warning (OPT_Wvla, 
-                 "variable length array is used");
+	warning_at (size_loc, OPT_Wvla,
+		    "variable length array is used");
     }
 
   if (processing_template_decl && !TREE_CONSTANT (size))
@@ -8942,7 +8953,7 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
 	{
 	  if (!(complain & tf_error))
 	    return error_mark_node;
-	  error ("overflow in array dimension");
+	  error_at (size_loc, "overflow in array dimension");
 	  TREE_OVERFLOW (itype) = 0;
 	}
     }
-- 
1.8.5.3

