[C++ Patch] Improve start_function and grokmethod locations

Paolo Carlini paolo.carlini@oracle.com
Tue Aug 6 13:57:00 GMT 2019


Hi,

apparently this is now easy to do, likely because a while ago I made 
sure that we consistently have meaningful locations for TYPE_DECLs too.

(I went through grokdeclarator and confirmed that when the third 
argument is FUNCDEF or MEMFUNCDEF it cannot return NULL_TREE)

Tested x86_64-linux.

Thanks, Paolo.

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


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

	* decl.c (start_function): Use DECL_SOURCE_LOCATION.
	(grokmethod): Likewise.

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

	* g++.dg/parse/typedef9.C: Test locations too.
-------------- next part --------------
Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 274141)
+++ cp/decl.c	(working copy)
@@ -15774,9 +15774,10 @@ start_function (cp_decl_specifier_seq *declspecs,
     return false;
   /* If the declarator is not suitable for a function definition,
      cause a syntax error.  */
-  if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL)
+  if (TREE_CODE (decl1) != FUNCTION_DECL)
     {
-      error ("invalid function declaration");
+      error_at (DECL_SOURCE_LOCATION (decl1),
+		"invalid function declaration");
       return false;
     }
 
@@ -16433,9 +16434,10 @@ grokmethod (cp_decl_specifier_seq *declspecs,
   if (fndecl == error_mark_node)
     return error_mark_node;
 
-  if (fndecl == NULL || TREE_CODE (fndecl) != FUNCTION_DECL)
+  if (TREE_CODE (fndecl) != FUNCTION_DECL)
     {
-      error ("invalid member function declaration");
+      error_at (DECL_SOURCE_LOCATION (fndecl),
+		"invalid member function declaration");
       return error_mark_node;
     }
 
Index: testsuite/g++.dg/parse/typedef9.C
===================================================================
--- testsuite/g++.dg/parse/typedef9.C	(revision 274140)
+++ testsuite/g++.dg/parse/typedef9.C	(working copy)
@@ -1,8 +1,8 @@
 // PR c++/38794
 // { dg-do compile }
 
-typedef void foo () {}	// { dg-error "invalid function declaration" }
+typedef void foo () {}	// { dg-error "14:invalid function declaration" }
 struct S
 {
-  typedef int bar (void) { return 0; } // { dg-error "invalid member function declaration" }
+  typedef int bar (void) { return 0; }  // { dg-error "15:invalid member function declaration" }
 };


More information about the Gcc-patches mailing list