[C++ Patch] Fix a start_decl location

Paolo Carlini paolo.carlini@oracle.com
Sun Jan 6 09:47:00 GMT 2019


Hi,

this was supposed to be very straightforward but required a little more. 
A first draft of the patch exploited DECL_SOURCE_LOCATION but that 
failed when I tested the case of a function already defined in class: at 
that point the location of the decl is that of the in class definition 
itself not that of the wrong redeclaration. Thus the use of 
declarator->id_loc. Tested x86_64-linux.

A final note, about a detail already noticed many other times: the 
location we store in such cases is that of K not that of f, and that 
seems suboptimal to me: in principle we should point to f and possibly 
have the wavy queue of the caret going back to K, at least that's what 
clang does... no idea id David has this kind of tweak in his todo list.

Thanks, Paolo.

////////////////////////

-------------- next part --------------
/cp
2019-01-06  Paolo Carlini  <paolo.carlini@oracle.com>

	* decl.c (start_decl): Improve permerror location.

/testsuite
2019-01-06  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/diagnostic/out-of-class-redeclaration.C: New.
-------------- next part --------------
Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 267600)
+++ cp/decl.c	(working copy)
@@ -5202,7 +5202,8 @@ start_decl (const cp_declarator *declarator,
       if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)
 	  /* Aliases are definitions. */
 	  && !alias)
-	permerror (input_location, "declaration of %q#D outside of class is not definition",
+	permerror (declarator->id_loc,
+		   "declaration of %q#D outside of class is not definition",
 		   decl);
     }
 
Index: testsuite/g++.dg/diagnostic/out-of-class-redeclaration.C
===================================================================
--- testsuite/g++.dg/diagnostic/out-of-class-redeclaration.C	(nonexistent)
+++ testsuite/g++.dg/diagnostic/out-of-class-redeclaration.C	(working copy)
@@ -0,0 +1,13 @@
+// Adapted from g++.old-deja/g++.law/arm8.C
+
+struct K {
+  void f(int);
+};
+
+void K::f(int);  // { dg-error "6:declaration of .void K::f\\(int\\). outside of class" }
+
+struct L {
+  void g(int) {}
+};
+
+void L::g(int);  // { dg-error "6:declaration of .void L::g\\(int\\). outside of class" }


More information about the Gcc-patches mailing list