cp-tree.h (class iloc_sentinel): New.
authorJason Merrill <jason@redhat.com>
Fri, 27 Sep 2019 18:19:55 +0000 (14:19 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 27 Sep 2019 18:19:55 +0000 (14:19 -0400)
* cp-tree.h (class iloc_sentinel): New.

We didn't already have a sentinel for input_location, and while
temp_override would work, it would also happily set input_location to 0,
which breaks things that try to look up the associated filename.

* decl.c (grokdeclarator, finish_enum_value_list): Use it.
* mangle.c (mangle_decl_string): Use it.
* pt.c (perform_typedefs_access_check): Use it.

From-SVN: r276191

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/mangle.c
gcc/cp/pt.c

index 3a3ef9ed2502016bda5fbb7f23a4c5c3bb931f22..8e92d91ef8e6592c1a9aef8b2ee99307dcf1bf4d 100644 (file)
@@ -1,3 +1,10 @@
+2019-09-27  Jason Merrill  <jason@redhat.com>
+
+       * cp-tree.h (class iloc_sentinel): New.
+       * decl.c (grokdeclarator, finish_enum_value_list): Use it.
+       * mangle.c (mangle_decl_string): Use it.
+       * pt.c (perform_typedefs_access_check): Use it.
+
 2019-09-27  Richard Sandiford  <richard.sandiford@arm.com>
 
        * cp-tree.h (build_cxx_call): Take the original function decl
index 8fc3fc1f78bad743116bbce549c1e41f080f7791..be1a44e437330be667811dce79cd9a4d08b2e77e 100644 (file)
@@ -1762,6 +1762,24 @@ public:
   ~warning_sentinel() { flag = val; }
 };
 
+/* RAII sentinel to temporarily override input_location.  This will not set
+   input_location to UNKNOWN_LOCATION or BUILTINS_LOCATION.  */
+
+class iloc_sentinel
+{
+  location_t saved_loc;
+public:
+  iloc_sentinel (location_t loc): saved_loc (input_location)
+  {
+    if (loc >= RESERVED_LOCATION_COUNT)
+      input_location = loc;
+  }
+  ~iloc_sentinel ()
+  {
+    input_location = saved_loc;
+  }
+};
+
 /* RAII sentinel that saves the value of a variable, optionally
    overrides it right away, and restores its value when the sentinel
    id destructed.  */
index b753796609a33cd8958655d757ef7a1688f1b87c..67c4521e98c70e6fe2718a54776b229a5ea6a3c7 100644 (file)
@@ -10523,7 +10523,6 @@ grokdeclarator (const cp_declarator *declarator,
   bool constinit_p = decl_spec_seq_has_spec_p (declspecs, ds_constinit);
   bool late_return_type_p = false;
   bool array_parameter_p = false;
-  location_t saved_loc = input_location;
   tree reqs = NULL_TREE;
 
   signed_p = decl_spec_seq_has_spec_p (declspecs, ds_signed);
@@ -11514,9 +11513,10 @@ grokdeclarator (const cp_declarator *declarator,
 
            /* Declaring a function type.  */
 
-           input_location = declspecs->locations[ds_type_spec];
-           abstract_virtuals_error (ACU_RETURN, type);
-           input_location = saved_loc;
+           {
+             iloc_sentinel ils (declspecs->locations[ds_type_spec]);
+             abstract_virtuals_error (ACU_RETURN, type);
+           }
 
            /* Pick up type qualifiers which should be applied to `this'.  */
            memfn_quals = declarator->u.function.qualifiers;
@@ -15061,11 +15061,8 @@ finish_enum_value_list (tree enumtype)
      type of the enumeration.  */
   for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
     {
-      location_t saved_location;
-
       decl = TREE_VALUE (values);
-      saved_location = input_location;
-      input_location = DECL_SOURCE_LOCATION (decl);
+      iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
       if (fixed_underlying_type_p)
         /* If the enumeration type has a fixed underlying type, we
            already checked all of the enumerator values.  */
@@ -15074,8 +15071,6 @@ finish_enum_value_list (tree enumtype)
         value = perform_implicit_conversion (underlying_type,
                                              DECL_INITIAL (decl),
                                              tf_warning_or_error);
-      input_location = saved_location;
-
       /* Do not clobber shared ints.  */
       if (value != error_mark_node)
        {
index 4d6f58093c1e7d177ee597d351fb78e55ecc6ac6..a9333b84349eb883aac6ef24a51e67e1f55abcad 100644 (file)
@@ -3791,7 +3791,6 @@ static tree
 mangle_decl_string (const tree decl)
 {
   tree result;
-  location_t saved_loc = input_location;
   tree saved_fn = NULL_TREE;
   bool template_p = false;
 
@@ -3809,7 +3808,7 @@ mangle_decl_string (const tree decl)
          current_function_decl = NULL_TREE;
        }
     }
-  input_location = DECL_SOURCE_LOCATION (decl);
+  iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
 
   start_mangling (decl);
 
@@ -3828,7 +3827,6 @@ mangle_decl_string (const tree decl)
       pop_tinst_level ();
       current_function_decl = saved_fn;
     }
-  input_location = saved_loc;
 
   return result;
 }
index e5d64989b328c350000115ebdba7cac9af8d6100..5a2dfbbd994f3699c9418aca993f883e61d40d8e 100644 (file)
@@ -10941,7 +10941,6 @@ apply_late_template_attributes (tree *decl_p, tree attributes, int attr_flags,
 static void
 perform_typedefs_access_check (tree tmpl, tree targs)
 {
-  location_t saved_location;
   unsigned i;
   qualified_typedef_usage_t *iter;
 
@@ -10950,7 +10949,6 @@ perform_typedefs_access_check (tree tmpl, tree targs)
          && TREE_CODE (tmpl) != FUNCTION_DECL))
     return;
 
-  saved_location = input_location;
   FOR_EACH_VEC_SAFE_ELT (get_types_needing_access_check (tmpl), i, iter)
     {
       tree type_decl = iter->typedef_decl;
@@ -10966,12 +10964,11 @@ perform_typedefs_access_check (tree tmpl, tree targs)
 
       /* Make access check error messages point to the location
          of the use of the typedef.  */
-      input_location = iter->locus;
+      iloc_sentinel ils (iter->locus);
       perform_or_defer_access_check (TYPE_BINFO (type_scope),
                                     type_decl, type_decl,
                                     tf_warning_or_error);
     }
-    input_location = saved_location;
 }
 
 static tree