diff mbox series

[C++] Add location_t parameter to grokvardecl

Message ID 9208064d-b9a0-66bf-416d-b89f975febb4@oracle.com
State New
Headers show
Series [C++] Add location_t parameter to grokvardecl | expand

Commit Message

Paolo Carlini Dec. 10, 2018, 10:23 a.m. UTC
Hi,

the other day I noticed that we weren't getting right the first location 
of pr53037-4.C, for a variable, whereas the next one, for a function, 
was Ok. Indeed, we were passing a location only to grokfndecl. In other 
terms, I found a good empirical reason to move the declaration of the 
local loc = declarator ? declarator->id_loc : input_location further up 
;) Tested x86_64-linux.

Thanks, Paolo.

//////////////////////
/cp
2018-12-10  Paolo Carlini  <paolo.carlini@oracle.com>

	* decl2.c (grokvardecl): Add location_t parameter and use it
	in build_lang_decl_loc and build_decl calls.
	(grokdeclarator): Move up loc declaration and use it in the
	grokvardecl call too.

/testsuite
2018-12-10  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/pr53037-4.C: Test the first two locations too.

Comments

Jason Merrill Dec. 11, 2018, 3:50 p.m. UTC | #1
On 12/10/18 5:23 AM, Paolo Carlini wrote:
> Hi,
> 
> the other day I noticed that we weren't getting right the first location 
> of pr53037-4.C, for a variable, whereas the next one, for a function, 
> was Ok. Indeed, we were passing a location only to grokfndecl. In other 
> terms, I found a good empirical reason to move the declaration of the 
> local loc = declarator ? declarator->id_loc : input_location further up 
> ;) Tested x86_64-linux.

OK.

Jason
diff mbox series

Patch

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 266943)
+++ cp/decl.c	(working copy)
@@ -68,7 +68,7 @@  static int decl_jump_unsafe (tree);
 static void require_complete_types_for_parms (tree);
 static tree grok_reference_init (tree, tree, tree, int);
 static tree grokvardecl (tree, tree, tree, const cp_decl_specifier_seq *,
-			 int, int, int, bool, int, tree);
+			 int, int, int, bool, int, tree, location_t);
 static void check_static_variable_definition (tree, tree);
 static void record_unknown_type (tree, const char *);
 static tree builtin_function_1 (tree, tree, bool);
@@ -9282,7 +9282,8 @@  grokvardecl (tree type,
 	     int inlinep,
 	     bool conceptp,
 	     int template_count,
-	     tree scope)
+	     tree scope,
+	     location_t location)
 {
   tree decl;
   tree explicit_scope;
@@ -9318,9 +9319,9 @@  grokvardecl (tree type,
 	  /* Similarly for explicit specializations.  */
 	  || (orig_declarator
 	      && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)))
-    decl = build_lang_decl (VAR_DECL, name, type);
+    decl = build_lang_decl_loc (location, VAR_DECL, name, type);
   else
-    decl = build_decl (input_location, VAR_DECL, name, type);
+    decl = build_decl (location, VAR_DECL, name, type);
 
   if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL)
     set_decl_namespace (decl, explicit_scope, 0);
@@ -12200,6 +12201,7 @@  grokdeclarator (const cp_declarator *declarator,
 
   {
     tree decl = NULL_TREE;
+    location_t loc = declarator ? declarator->id_loc : input_location;
 
     if (decl_context == PARM)
       {
@@ -12216,13 +12218,13 @@  grokdeclarator (const cp_declarator *declarator,
 	if (!staticp && !friendp && TREE_CODE (type) != METHOD_TYPE)
 	  if (tree auto_node = type_uses_auto (type))
 	    {
-	      location_t loc = declspecs->locations[ds_type_spec];
+	      location_t tloc = declspecs->locations[ds_type_spec];
 	      if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
-		error_at (loc, "invalid use of template-name %qE without an "
+		error_at (tloc, "invalid use of template-name %qE without an "
 			  "argument list",
 			  CLASS_PLACEHOLDER_TEMPLATE (auto_node));
 	      else
-		error_at (loc, "non-static data member declared with "
+		error_at (tloc, "non-static data member declared with "
 			  "placeholder %qT", auto_node);
 	      type = error_mark_node;
 	    }
@@ -12487,7 +12489,6 @@  grokdeclarator (const cp_declarator *declarator,
 
 	if (decl == NULL_TREE)
 	  {
-	    location_t loc = declarator ? declarator->id_loc : input_location;
 	    if (staticp)
 	      {
 		/* C++ allows static class members.  All other work
@@ -12704,7 +12705,8 @@  grokdeclarator (const cp_declarator *declarator,
 			    inlinep,
 			    concept_p,
 			    template_count,
-			    ctype ? ctype : in_namespace);
+			    ctype ? ctype : in_namespace,
+			    loc);
 	if (decl == NULL_TREE)
 	  return error_mark_node;
 
Index: testsuite/g++.dg/pr53037-4.C
===================================================================
--- testsuite/g++.dg/pr53037-4.C	(revision 266943)
+++ testsuite/g++.dg/pr53037-4.C	(working copy)
@@ -2,11 +2,11 @@ 
 /* { dg-do compile } */
 /* { dg-options "-O0" } */
 
-int foo1 __attribute__((warn_if_not_aligned(8))); /* { dg-error "'warn_if_not_aligned' may not be specified for 'foo1'" } */
+int foo1 __attribute__((warn_if_not_aligned(8))); /* { dg-error "5:'warn_if_not_aligned' may not be specified for 'foo1'" } */
 
 __attribute__((warn_if_not_aligned(8)))
 void
-foo2 (void) /* { dg-error "'warn_if_not_aligned' may not be specified for 'void foo2\\(\\)'" } */
+foo2 (void) /* { dg-error "1:'warn_if_not_aligned' may not be specified for 'void foo2\\(\\)'" } */
 {
 }