diff mbox series

[C++] Use DECL_SOURCE_LOCATION more in name-lookup.c

Message ID be5f4bfa-e905-1800-ef9e-0c63f02986d0@oracle.com
State New
Headers show
Series [C++] Use DECL_SOURCE_LOCATION more in name-lookup.c | expand

Commit Message

Paolo Carlini Sept. 24, 2019, 7:07 p.m. UTC
Hi,

Marek's recent fix prompted an audit of name-lookup.c and I found a few 
additional straightforward places where we should use a more accurate 
location. Tested x86_64-linux.

Thanks, Paolo.

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

	* name-lookup.c (check_extern_c_conflict): Use DECL_SOURCE_LOCATION.
	(check_local_shadow): Use it in three additional places.

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

	* g++.dg/diagnostic/redeclaration-1.C: New.
	* g++.dg/lookup/extern-c-hidden.C: Test location(s) too.
	* g++.dg/lookup/extern-c-redecl.C: Likewise.
	* g++.dg/lookup/extern-c-redecl6.C: Likewise.
	* g++.old-deja/g++.other/using9.C: Likewise.

Comments

Marek Polacek Sept. 24, 2019, 7:34 p.m. UTC | #1
On Tue, Sep 24, 2019 at 09:07:03PM +0200, Paolo Carlini wrote:
> Hi,
> 
> Marek's recent fix prompted an audit of name-lookup.c and I found a few
> additional straightforward places where we should use a more accurate
> location. Tested x86_64-linux.
> 
> Thanks, Paolo.
> 
> ///////////////////////
> 

> /cp
> 2019-09-24  Paolo Carlini  <paolo.carlini@oracle.com>
> 
> 	* name-lookup.c (check_extern_c_conflict): Use DECL_SOURCE_LOCATION.
> 	(check_local_shadow): Use it in three additional places.
> 
> /testsuite
> 2019-09-24  Paolo Carlini  <paolo.carlini@oracle.com>
> 
> 	* g++.dg/diagnostic/redeclaration-1.C: New.
> 	* g++.dg/lookup/extern-c-hidden.C: Test location(s) too.
> 	* g++.dg/lookup/extern-c-redecl.C: Likewise.
> 	* g++.dg/lookup/extern-c-redecl6.C: Likewise.
> 	* g++.old-deja/g++.other/using9.C: Likewise.

LGTM.

Marek
Jason Merrill Sept. 25, 2019, 1:09 p.m. UTC | #2
On 9/24/19 3:34 PM, Marek Polacek wrote:
> On Tue, Sep 24, 2019 at 09:07:03PM +0200, Paolo Carlini wrote:
>> Hi,
>>
>> Marek's recent fix prompted an audit of name-lookup.c and I found a few
>> additional straightforward places where we should use a more accurate
>> location. Tested x86_64-linux.
>>
>> Thanks, Paolo.
>>
>> ///////////////////////
>>
> 
>> /cp
>> 2019-09-24  Paolo Carlini  <paolo.carlini@oracle.com>
>>
>> 	* name-lookup.c (check_extern_c_conflict): Use DECL_SOURCE_LOCATION.
>> 	(check_local_shadow): Use it in three additional places.
>>
>> /testsuite
>> 2019-09-24  Paolo Carlini  <paolo.carlini@oracle.com>
>>
>> 	* g++.dg/diagnostic/redeclaration-1.C: New.
>> 	* g++.dg/lookup/extern-c-hidden.C: Test location(s) too.
>> 	* g++.dg/lookup/extern-c-redecl.C: Likewise.
>> 	* g++.dg/lookup/extern-c-redecl6.C: Likewise.
>> 	* g++.old-deja/g++.other/using9.C: Likewise.
> 
> LGTM.
> 
> Marek

OK.

Jason
diff mbox series

Patch

Index: cp/name-lookup.c
===================================================================
--- cp/name-lookup.c	(revision 276104)
+++ cp/name-lookup.c	(working copy)
@@ -2549,12 +2549,12 @@  check_extern_c_conflict (tree decl)
       if (mismatch)
 	{
 	  auto_diagnostic_group d;
-	  pedwarn (input_location, 0,
+	  pedwarn (DECL_SOURCE_LOCATION (decl), 0,
 		   "conflicting C language linkage declaration %q#D", decl);
 	  inform (DECL_SOURCE_LOCATION (old),
 		  "previous declaration %q#D", old);
 	  if (mismatch < 0)
-	    inform (input_location,
+	    inform (DECL_SOURCE_LOCATION (decl),
 		    "due to different exception specifications");
 	}
       else
@@ -2674,7 +2674,8 @@  check_local_shadow (tree decl)
 	  /* ARM $8.3 */
 	  if (b->kind == sk_function_parms)
 	    {
-	      error ("declaration of %q#D shadows a parameter", decl);
+	      error_at (DECL_SOURCE_LOCATION (decl),
+			"declaration of %q#D shadows a parameter", decl);
 	      return;
 	    }
 	}
@@ -2700,7 +2701,8 @@  check_local_shadow (tree decl)
 	       && (old_scope->kind == sk_cond || old_scope->kind == sk_for))
 	{
 	  auto_diagnostic_group d;
-	  error ("redeclaration of %q#D", decl);
+	  error_at (DECL_SOURCE_LOCATION (decl),
+		    "redeclaration of %q#D", decl);
 	  inform (DECL_SOURCE_LOCATION (old),
 		  "%q#D previously declared here", old);
 	  return;
@@ -2723,7 +2725,8 @@  check_local_shadow (tree decl)
 		   && in_function_try_handler))
 	{
 	  auto_diagnostic_group d;
-	  if (permerror (input_location, "redeclaration of %q#D", decl))
+	  if (permerror (DECL_SOURCE_LOCATION (decl),
+			 "redeclaration of %q#D", decl))
 	    inform (DECL_SOURCE_LOCATION (old),
 		    "%q#D previously declared here", old);
 	  return;
Index: testsuite/g++.dg/diagnostic/redeclaration-1.C
===================================================================
--- testsuite/g++.dg/diagnostic/redeclaration-1.C	(nonexistent)
+++ testsuite/g++.dg/diagnostic/redeclaration-1.C	(working copy)
@@ -0,0 +1,20 @@ 
+void
+foo (int i)
+{
+  int i  // { dg-error "7:declaration of .int i. shadows a parameter" }
+    (0);
+  
+  for (int j ;;)
+    int j  // { dg-error "9:redeclaration of .int j." }
+      (0);
+}
+
+void
+bar (int i)
+  try
+    { }
+  catch (...)
+    {
+      int i  // { dg-error "11:redeclaration of .int i." }
+	(0);
+    }
Index: testsuite/g++.dg/lookup/extern-c-hidden.C
===================================================================
--- testsuite/g++.dg/lookup/extern-c-hidden.C	(revision 276104)
+++ testsuite/g++.dg/lookup/extern-c-hidden.C	(working copy)
@@ -4,8 +4,8 @@  extern "C" float fabsf (float);  // { dg-message "
 
 namespace Bob 
 {
-  extern "C" float fabsf (float, float); // { dg-error "C language" }
+  extern "C" float fabsf (float, float); // { dg-error "20:conflicting C language" }
   extern "C" double fabs (double, double); // { dg-message "previous declaration" }
 }
 
-extern "C" double fabs (double); // { dg-error "C language" }
+extern "C" double fabs (double); // { dg-error "19:conflicting C language" }
Index: testsuite/g++.dg/lookup/extern-c-redecl.C
===================================================================
--- testsuite/g++.dg/lookup/extern-c-redecl.C	(revision 276104)
+++ testsuite/g++.dg/lookup/extern-c-redecl.C	(working copy)
@@ -8,4 +8,4 @@  namespace A {
 // next line should trigger an error because
 // it conflicts with previous declaration of foo_func (), due to
 // different exception specifications.
-extern "C" void foo_func (); // { dg-error "C language linkage|exception specifications" }
+extern "C" void foo_func (); // { dg-error "17:conflicting C language linkage|exception specifications" }
Index: testsuite/g++.dg/lookup/extern-c-redecl6.C
===================================================================
--- testsuite/g++.dg/lookup/extern-c-redecl6.C	(revision 276104)
+++ testsuite/g++.dg/lookup/extern-c-redecl6.C	(working copy)
@@ -16,10 +16,10 @@  extern "C" {
 
   namespace BAD
   {
-    long i; // { dg-error "C language linkage" }
-    double f; // { dg-error "C language linkage" }
-    int fn (); // { dg-error "C language linkage" }
-    int ai1[2]; // { dg-error "C language linkage" }
+    long i; // { dg-error "10:conflicting C language linkage" }
+    double f; // { dg-error "12:conflicting C language linkage" }
+    int fn (); // { dg-error "9:conflicting C language linkage" }
+    int ai1[2]; // { dg-error "9:conflicting C language linkage" }
   }
 }
 
Index: testsuite/g++.old-deja/g++.other/using9.C
===================================================================
--- testsuite/g++.old-deja/g++.other/using9.C	(revision 276104)
+++ testsuite/g++.old-deja/g++.other/using9.C	(working copy)
@@ -16,6 +16,6 @@  using ::a;
 extern "C" void foo ();		// { dg-message "previous declaration" }
 
 namespace {
-  extern "C" int foo ();	// { dg-error "C.*linkage" }
+  extern "C" int foo ();	// { dg-error "18:conflicting C.*linkage" }
   using ::foo; // { dg-error "" } already in use
 }