diff mbox series

[C++] More cp_expr_loc_or_input_loc and DECL_SOURCE_LOCATION uses

Message ID 53d44e84-8a4e-c750-1f91-df7abfcfd9c6@oracle.com
State New
Headers show
Series [C++] More cp_expr_loc_or_input_loc and DECL_SOURCE_LOCATION uses | expand

Commit Message

Paolo Carlini Sept. 30, 2019, 12:24 p.m. UTC
Hi,

a few more in init.c and name-lookup.c, respectively. Tested 
x86_64-linux, as usual.

Thanks, Paolo.

///////////////////////////
/cp
2019-09-30  Paolo Carlini  <paolo.carlini@oracle.com>

	* init.c (build_new): Use cp_expr_loc_or_input_loc in two places.
	* name-lookup.c (do_pushdecl): Use DECL_SOURCE_LOCATION.
	(push_class_level_binding_1): Likewise.
	(set_decl_namespace): Likewise.

/testsuite
2019-09-30  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/diagnostic/integral-array-size-1.C: New.
	* g++.dg/cpp0x/alias-decl-1.C: Test location(s) too.
	* g++.dg/init/new43.C: Likewise.
	* g++.dg/lookup/friend12.C: Likewise.
	* g++.dg/lookup/pr79766.C: Likewise.
	* g++.dg/lookup/pr84375.C: Likewise.
	* g++.dg/other/new-size-type.C: Likewise.

Comments

Jason Merrill Oct. 2, 2019, 4:12 p.m. UTC | #1
On 9/30/19 8:24 AM, Paolo Carlini wrote:
> Hi,
> 
> a few more in init.c and name-lookup.c, respectively. Tested 
> x86_64-linux, as usual.
> 
> Thanks, Paolo.
> 
> ///////////////////////////
> 
OK.
diff mbox series

Patch

Index: cp/init.c
===================================================================
--- cp/init.c	(revision 276151)
+++ cp/init.c	(working copy)
@@ -3759,7 +3759,8 @@  build_new (vec<tree, va_gc> **placement, tree type
       if (!build_expr_type_conversion (WANT_INT | WANT_ENUM, nelts, false))
         {
           if (complain & tf_error)
-            permerror (input_location, "size in array new must have integral type");
+	    permerror (cp_expr_loc_or_input_loc (nelts),
+		       "size in array new must have integral type");
           else
             return error_mark_node;
         }
@@ -3774,7 +3775,8 @@  build_new (vec<tree, va_gc> **placement, tree type
 	 less than zero. ... If the expression is a constant expression,
 	 the program is ill-fomed.  */
       if (TREE_CODE (cst_nelts) == INTEGER_CST
-	  && !valid_array_size_p (input_location, cst_nelts, NULL_TREE,
+	  && !valid_array_size_p (cp_expr_loc_or_input_loc (nelts),
+				  cst_nelts, NULL_TREE,
 				  complain & tf_error))
 	return error_mark_node;
 
Index: cp/name-lookup.c
===================================================================
--- cp/name-lookup.c	(revision 276151)
+++ cp/name-lookup.c	(working copy)
@@ -3080,8 +3080,9 @@  do_pushdecl (tree decl, bool is_friend)
 		  /* In a local class, a friend function declaration must
 		     find a matching decl in the innermost non-class scope.
 		     [class.friend/11] */
-		  error ("friend declaration %qD in local class without "
-			 "prior local declaration", decl);
+		  error_at (DECL_SOURCE_LOCATION (decl),
+			    "friend declaration %qD in local class without "
+			    "prior local declaration", decl);
 		  /* Don't attempt to push it.  */
 		  return error_mark_node;
 		}
@@ -4451,9 +4452,9 @@  push_class_level_binding_1 (tree name, tree x)
       tree scope = context_for_name_lookup (x);
       if (TYPE_P (scope) && same_type_p (scope, current_class_type))
 	{
-	  error ("%qD has the same name as the class in which it is "
-		 "declared",
-		 x);
+	  error_at (DECL_SOURCE_LOCATION (x),
+		    "%qD has the same name as the class in which it is "
+		    "declared", x);
 	  return false;
 	}
     }
@@ -4757,7 +4758,8 @@  set_decl_namespace (tree decl, tree scope, bool fr
       /* Writing "N::i" to declare something directly in "N" is invalid.  */
       if (CP_DECL_CONTEXT (decl) == current_namespace
 	  && at_namespace_scope_p ())
-	error ("explicit qualification in declaration of %qD", decl);
+	error_at (DECL_SOURCE_LOCATION (decl),
+		  "explicit qualification in declaration of %qD", decl);
       return;
     }
 
Index: testsuite/g++.dg/cpp0x/alias-decl-1.C
===================================================================
--- testsuite/g++.dg/cpp0x/alias-decl-1.C	(revision 276151)
+++ testsuite/g++.dg/cpp0x/alias-decl-1.C	(working copy)
@@ -12,5 +12,5 @@  template<class U> struct Ptr<U*> {}; // { dg-error
 
 struct A {
     using A = int;  // { dg-error "11:ISO C\\+\\+ forbids nested type .A." }
-// { dg-error "same name as" "" { target c++11 } .-1 }  
+// { dg-error "11:.using A = int. has the same name as" "" { target c++11 } .-1 }  
 };
Index: testsuite/g++.dg/diagnostic/integral-array-size-1.C
===================================================================
--- testsuite/g++.dg/diagnostic/integral-array-size-1.C	(nonexistent)
+++ testsuite/g++.dg/diagnostic/integral-array-size-1.C	(working copy)
@@ -0,0 +1,7 @@ 
+template<typename T>
+void foo(T a)
+{
+  new int[a];  // { dg-error "11:size in array new must have integral type" }
+}
+
+template void foo(float);
Index: testsuite/g++.dg/init/new43.C
===================================================================
--- testsuite/g++.dg/init/new43.C	(revision 276151)
+++ testsuite/g++.dg/init/new43.C	(working copy)
@@ -30,36 +30,36 @@  void test_literal ()
     B b;
 
     // Verify integer literal.
-    p = new char [-1];           // { dg-error "size .-1. of array is negative" }
-    p = new char [2][-3];        // { dg-error "size .-3. of array|narrowing conversion" }
-    p = new char [-4][5];        // { dg-error "size .-4. of array is negative" }
-    p = new char [-6][-7];       // { dg-error "size .-\[67\]. of array|narrowing conversion" }
-
-    p = new (p) char [-1];       // { dg-error "size .-1. of array is negative" }
-    p = new (p) char [2][-3];    // { dg-error "size .-3. of array|narrowing conversion" }
-    p = new (p) char [-4][5];    // { dg-error "size .-4. of array is negative" }
-    p = new (p) char [-6][-7];   // { dg-error "size .-\[67\]. of array|narrowing conversion" }
-
-    p = new (p) A [-1];          // { dg-error "size .-1. of array is negative" }
-    p = new (p) A [2][-3];       // { dg-error "size .-3. of array|narrowing conversion" }
-    p = new (p) A [-4][5];       // { dg-error "size .-4. of array is negative" }
-    p = new (p) A [-6][-7];      // { dg-error "size .-\[67\]. of array|narrowing conversion" }
-
-    p = new (p) B [-1];          // { dg-error "size .-1. of array is negative" }
-    p = new (p) B [2][-3];       // { dg-error "size .-3. of array|narrowing conversion" }
-    p = new (p) B [-4][5];       // { dg-error "size .-4. of array is negative" }
-    p = new (p) B [-6][-7];      // { dg-error "size .-\[67\]. of array|narrowing conversion" }
-
-    p = new (&b) B [-1];          // { dg-error "size .-1. of array is negative" }
-    p = new (&b) B [2][-3];       // { dg-error "size .-3. of array|narrowing conversion" }
-    p = new (&b) B [-4][5];       // { dg-error "size .-4. of array is negative" }
-    p = new (&b) B [-6][-7];      // { dg-error "size .-\[67\]. of array|narrowing conversion" }
-
-    p = new char [1 - 2];         // { dg-error "size .-1. of array is negative" }
-    p = new (p) char [2 - 3];     // { dg-error "size .-1. of array is negative" }
-    p = new A [2 < 1 ? -1 : -2];  // { dg-error "size .-2. of array is negative" }
-    p = new (p) B [2 - 3 * 2];    // { dg-error "size .-4. of array is negative" }
-    p = new (&b) B [1][2 - 3 * 2];// { dg-error "size .-4. of array|narrowing conversion" }
+    p = new char [-1];           // { dg-error "19:size .-1. of array is negative" }
+    p = new char [2][-3];        // { dg-error "22:size .-3. of array|narrowing conversion" }
+    p = new char [-4][5];        // { dg-error "19:size .-4. of array is negative" }
+    p = new char [-6][-7];       // { dg-error "19:size .-6. of array|narrowing conversion" }
+    // { dg-error "23:size .-7. of array" "" { target *-*-* } .-1 }
+    p = new (p) char [-1];       // { dg-error "23:size .-1. of array is negative" }
+    p = new (p) char [2][-3];    // { dg-error "26:size .-3. of array|narrowing conversion" }
+    p = new (p) char [-4][5];    // { dg-error "23:size .-4. of array is negative" }
+    p = new (p) char [-6][-7];   // { dg-error "23:size .-6. of array|narrowing conversion" }
+    // { dg-error "27:size .-7. of array" "" { target *-*-* } .-1 }
+    p = new (p) A [-1];          // { dg-error "20:size .-1. of array is negative" }
+    p = new (p) A [2][-3];       // { dg-error "23:size .-3. of array|narrowing conversion" }
+    p = new (p) A [-4][5];       // { dg-error "20:size .-4. of array is negative" }
+    p = new (p) A [-6][-7];      // { dg-error "20:size .-6. of array|narrowing conversion" }
+    // { dg-error "24:size .-7. of array" "" { target *-*-* } .-1 }
+    p = new (p) B [-1];          // { dg-error "20:size .-1. of array is negative" }
+    p = new (p) B [2][-3];       // { dg-error "23:size .-3. of array|narrowing conversion" }
+    p = new (p) B [-4][5];       // { dg-error "20:size .-4. of array is negative" }
+    p = new (p) B [-6][-7];      // { dg-error "size .-6. of array|narrowing conversion" }
+    // { dg-error "24:size .-7. of array" "" { target *-*-* } .-1 }
+    p = new (&b) B [-1];          // { dg-error "21:size .-1. of array is negative" }
+    p = new (&b) B [2][-3];       // { dg-error "24:size .-3. of array|narrowing conversion" }
+    p = new (&b) B [-4][5];       // { dg-error "21:size .-4. of array is negative" }
+    p = new (&b) B [-6][-7];      // { dg-error "21:size .-6. of array|narrowing conversion" }
+    // { dg-error "25:size .-7. of array" "" { target *-*-* } .-1 }
+    p = new char [1 - 2];         // { dg-error "21:size .-1. of array is negative" }
+    p = new (p) char [2 - 3];     // { dg-error "25:size .-1. of array is negative" }
+    p = new A [2 < 1 ? -1 : -2];  // { dg-error "22:size .-2. of array is negative" }
+    p = new (p) B [2 - 3 * 2];    // { dg-error "22:size .-4. of array is negative" }
+    p = new (&b) B [1][2 - 3 * 2];// { dg-error "26:size .-4. of array|narrowing conversion" }
 }
 
 void test_constant_expression ()
@@ -78,36 +78,36 @@  void test_constant_expression ()
     static const int i7 = -7;
 
     // Verify constant expression.
-    p = new char [i1];           // { dg-error "size .-1. of array is negative" }
-    p = new char [2][i3];        // { dg-error "size .-3. of array|narrowing conversion" }
-    p = new char [i4][5];        // { dg-error "size .-4. of array is negative" }
-    p = new char [i6][i7];       // { dg-error "size .-\[67\]. of array|narrowing conversion" }
-
-    p = new (p) char [i1];       // { dg-error "size .-1. of array is negative" }
-    p = new (p) char [2][i3];    // { dg-error "size .-3. of array|narrowing conversion" }
-    p = new (p) char [i4][5];    // { dg-error "size .-4. of array is negative" }
-    p = new (p) char [i6][i7];   // { dg-error "size .-\[67\]. of array|narrowing conversion" }
-
-    p = new (p) A [i1];          // { dg-error "size .-1. of array is negative" }
-    p = new (p) A [2][i3];       // { dg-error "size .-3. of array|narrowing conversion" }
-    p = new (p) A [i4][5];       // { dg-error "size .-4. of array is negative" }
-    p = new (p) A [i6][i7];      // { dg-error "size .-\[67\]. of array|narrowing conversion" }
-
-    p = new (p) B [i1];          // { dg-error "size .-1. of array is negative" }
-    p = new (p) B [2][i3];       // { dg-error "size .-3. of array|narrowing conversion" }
-    p = new (p) B [i4][5];       // { dg-error "size .-4. of array is negative" }
-    p = new (p) B [i6][i7];      // { dg-error "size .-\[67\]. of array|narrowing conversion" }
-
-    p = new (&b) B [i1];          // { dg-error "size .-1. of array is negative" }
-    p = new (&b) B [2][i3];       // { dg-error "size .-3. of array|narrowing conversion" }
-    p = new (&b) B [i4][5];       // { dg-error "size .-4. of array is negative" }
-    p = new (&b) B [i6][i7];      // { dg-error "size .-\[67\]. of array|narrowing conversion" }
-
-    p = new short [i1 - 2];       // { dg-error "size .-3. of array is negative" }
-    p = new (p) bool [i2 - 3];    // { dg-error "size .-5. of array is negative" }
-    p = new A [2 < 1 ? i1 : i2];  // { dg-error "size .-2. of array is negative" }
-    p = new (p) B [2 + i3 * 2];   // { dg-error "size .-4. of array is negative" }
-    p = new (&b) B [1][i1 - 3 * 2];// { dg-error "size .-7. of array|narrowing conversion" }
+    p = new char [i1];           // { dg-error "19:size .-1. of array is negative" }
+    p = new char [2][i3];        // { dg-error "22:size .-3. of array|narrowing conversion" }
+    p = new char [i4][5];        // { dg-error "19:size .-4. of array is negative" }
+    p = new char [i6][i7];       // { dg-error "19:size .-6. of array|narrowing conversion" }
+    // { dg-error "23:size .-7. of array" "" { target *-*-* } .-1 }
+    p = new (p) char [i1];       // { dg-error "23:size .-1. of array is negative" }
+    p = new (p) char [2][i3];    // { dg-error "26:size .-3. of array|narrowing conversion" }
+    p = new (p) char [i4][5];    // { dg-error "23:size .-4. of array is negative" }
+    p = new (p) char [i6][i7];   // { dg-error "23:size .-6. of array|narrowing conversion" }
+    // { dg-error "27:size .-7. of array" "" { target *-*-* } .-1 }
+    p = new (p) A [i1];          // { dg-error "20:size .-1. of array is negative" }
+    p = new (p) A [2][i3];       // { dg-error "23:size .-3. of array|narrowing conversion" }
+    p = new (p) A [i4][5];       // { dg-error "20:size .-4. of array is negative" }
+    p = new (p) A [i6][i7];      // { dg-error "20:size .-6. of array|narrowing conversion" }
+    // { dg-error "24:size .-7. of array" "" { target *-*-* } .-1 }
+    p = new (p) B [i1];          // { dg-error "20:size .-1. of array is negative" }
+    p = new (p) B [2][i3];       // { dg-error "23:size .-3. of array|narrowing conversion" }
+    p = new (p) B [i4][5];       // { dg-error "20:size .-4. of array is negative" }
+    p = new (p) B [i6][i7];      // { dg-error "20:size .-6. of array|narrowing conversion" }
+    // { dg-error "24:size .-7. of array" "" { target *-*-* } .-1 }
+    p = new (&b) B [i1];          // { dg-error "21:size .-1. of array is negative" }
+    p = new (&b) B [2][i3];       // { dg-error "24:size .-3. of array|narrowing conversion" }
+    p = new (&b) B [i4][5];       // { dg-error "21:size .-4. of array is negative" }
+    p = new (&b) B [i6][i7];      // { dg-error "21:size .-6. of array|narrowing conversion" }
+    // { dg-error "25:size .-7. of array" "" { target *-*-* } .-1 }
+    p = new short [i1 - 2];       // { dg-error "23:size .-3. of array is negative" }
+    p = new (p) bool [i2 - 3];    // { dg-error "26:size .-5. of array is negative" }
+    p = new A [2 < 1 ? i1 : i2];  // { dg-error "22:size .-2. of array is negative" }
+    p = new (p) B [2 + i3 * 2];   // { dg-error "22:size .-4. of array is negative" }
+    p = new (&b) B [1][i1 - 3 * 2];// { dg-error "27:size .-7. of array|narrowing conversion" }
 }
 
 void test_constexpr ()
@@ -131,36 +131,36 @@  void test_constexpr ()
 #endif
 
     // Verify constant expression.
-    p = new char [s1];           // { dg-error "size .-1. of array is negative" }
-    p = new char [2][s3];        // { dg-error "size .-3. of array|narrowing conversion" }
-    p = new char [s4][5];        // { dg-error "size .-4. of array is negative" }
-    p = new char [s6][s7];       // { dg-error "size .-\[67\]. of array|narrowing conversion" }
-
-    p = new (p) char [s1];       // { dg-error "size .-1. of array is negative" }
-    p = new (p) char [2][s3];    // { dg-error "size .-3. of array|narrowing conversion" }
-    p = new (p) char [s4][5];    // { dg-error "size .-4. of array is negative" }
-    p = new (p) char [s6][s7];   // { dg-error "size .-\[67\]. of array|narrowing conversion" }
-
-    p = new (p) A [s1];          // { dg-error "size .-1. of array is negative" }
-    p = new (p) A [2][s3];       // { dg-error "size .-3. of array|narrowing conversion" }
-    p = new (p) A [s4][5];       // { dg-error "size .-4. of array is negative" }
-    p = new (p) A [s6][s7];      // { dg-error "size .-\[67\]. of array|narrowing conversion" }
-
-    p = new (p) B [s1];          // { dg-error "size .-1. of array is negative" }
-    p = new (p) B [2][s3];       // { dg-error "size .-3. of array|narrowing conversion" }
-    p = new (p) B [s4][5];       // { dg-error "size .-4. of array is negative" }
-    p = new (p) B [s6][s7];      // { dg-error "size .-\[67\]. of array|narrowing conversion" }
-
-    p = new (&b) B [s1];          // { dg-error "size .-1. of array is negative" }
-    p = new (&b) B [2][s3];       // { dg-error "size .-3. of array|narrowing conversion" }
-    p = new (&b) B [s4][5];       // { dg-error "size .-4. of array is negative" }
-    p = new (&b) B [s6][s7];      // { dg-error "size .-\[67\]. of array|narrowing conversion" }
-
-    p = new int [s1 + s2];           // { dg-error "size .-3. of array is negative" }
-    p = new (p) long [2 * s3];       // { dg-error "size .-6. of array is negative" }
+    p = new char [s1];           // { dg-error "19:size .-1. of array is negative" }
+    p = new char [2][s3];        // { dg-error "22:size .-3. of array|narrowing conversion" }
+    p = new char [s4][5];        // { dg-error "19:size .-4. of array is negative" }
+    p = new char [s6][s7];       // { dg-error "19:size .-6. of array|narrowing conversion" }
+    // { dg-error "23:size .-7. of array" "" { target *-*-* } .-1 }
+    p = new (p) char [s1];       // { dg-error "23:size .-1. of array is negative" }
+    p = new (p) char [2][s3];    // { dg-error "26:size .-3. of array|narrowing conversion" }
+    p = new (p) char [s4][5];    // { dg-error "23:size .-4. of array is negative" }
+    p = new (p) char [s6][s7];   // { dg-error "23:size .-6. of array|narrowing conversion" }
+    // { dg-error "27:size .-7. of array" "" { target *-*-* } .-1 }
+    p = new (p) A [s1];          // { dg-error "20:size .-1. of array is negative" }
+    p = new (p) A [2][s3];       // { dg-error "23:size .-3. of array|narrowing conversion" }
+    p = new (p) A [s4][5];       // { dg-error "20:size .-4. of array is negative" }
+    p = new (p) A [s6][s7];      // { dg-error "20:size .-6. of array|narrowing conversion" }
+    // { dg-error "24:size .-7. of array" "" { target *-*-* } .-1 }
+    p = new (p) B [s1];          // { dg-error "20:size .-1. of array is negative" }
+    p = new (p) B [2][s3];       // { dg-error "23:size .-3. of array|narrowing conversion" }
+    p = new (p) B [s4][5];       // { dg-error "20:size .-4. of array is negative" }
+    p = new (p) B [s6][s7];      // { dg-error "20:size .-6. of array|narrowing conversion" }
+    // { dg-error "24:size .-7. of array" "" { target *-*-* } .-1 }
+    p = new (&b) B [s1];          // { dg-error "21:size .-1. of array is negative" }
+    p = new (&b) B [2][s3];       // { dg-error "24:size .-3. of array|narrowing conversion" }
+    p = new (&b) B [s4][5];       // { dg-error "21:size .-4. of array is negative" }
+    p = new (&b) B [s6][s7];      // { dg-error "21:size .-6. of array|narrowing conversion" }
+    // { dg-error "25:size .-7. of array" "" { target *-*-* } .-1 }
+    p = new int [s1 + s2];           // { dg-error "21:size .-3. of array is negative" }
+    p = new (p) long [2 * s3];       // { dg-error "25:size .-6. of array is negative" }
     p = new A [s2 < s1 ? s1 : s2];   // { dg-error "size .-1. of array is negative" }
-    p = new (p) B [s7 - s2 * 2];     // { dg-error "size .-3. of array is negative" }
-    p = new (&b) B [9][s4 - s1 * 2]; // { dg-error "size .-2. of array|narrowing conversion" }
+    p = new (p) B [s7 - s2 * 2];     // { dg-error "23:size .-3. of array is negative" }
+    p = new (&b) B [9][s4 - s1 * 2]; // { dg-error "27:size .-2. of array|narrowing conversion" }
 }
 
 /* Prune out pedantic warnins (turned into errors via -pedantic-errors).
Index: testsuite/g++.dg/lookup/friend12.C
===================================================================
--- testsuite/g++.dg/lookup/friend12.C	(revision 276151)
+++ testsuite/g++.dg/lookup/friend12.C	(working copy)
@@ -5,6 +5,6 @@  void foo()
   extern void bar (int); // not the bar we are looking for
   struct A
   {
-    friend void bar();	// { dg-error "without prior local declaration" }
+    friend void bar();	// { dg-error "17:friend declaration .void bar\\(\\). in local class without prior local declaration" }
   };
 }
Index: testsuite/g++.dg/lookup/pr79766.C
===================================================================
--- testsuite/g++.dg/lookup/pr79766.C	(revision 276151)
+++ testsuite/g++.dg/lookup/pr79766.C	(working copy)
@@ -24,6 +24,6 @@  void ::R () // OK -> Z::R
 
 void S ();
 
-void ::S () // { dg-error "explicit qualification" }
+void ::S () // { dg-error "6:explicit qualification" }
 {
 }
Index: testsuite/g++.dg/lookup/pr84375.C
===================================================================
--- testsuite/g++.dg/lookup/pr84375.C	(revision 276151)
+++ testsuite/g++.dg/lookup/pr84375.C	(working copy)
@@ -4,6 +4,6 @@  void foo()
 {
   struct A
   {
-    friend void A(); // { dg-error "local class without prior local" }
+    friend void A(); // { dg-error "17:friend declaration .void A\\(\\). in local class without prior local" }
   };
 }
Index: testsuite/g++.dg/other/new-size-type.C
===================================================================
--- testsuite/g++.dg/other/new-size-type.C	(revision 276151)
+++ testsuite/g++.dg/other/new-size-type.C	(working copy)
@@ -5,5 +5,5 @@ 
 const char*
 foo()
 {
-    return new char[~static_cast<size_t>(0)];// { dg-error "exceeds maximum object size" }
+    return new char[~static_cast<size_t>(0)];// { dg-error "21:exceeds maximum object size" }
 }