* 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
+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
~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. */
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);
/* 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;
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. */
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)
{
mangle_decl_string (const tree decl)
{
tree result;
- location_t saved_loc = input_location;
tree saved_fn = NULL_TREE;
bool template_p = false;
current_function_decl = NULL_TREE;
}
}
- input_location = DECL_SOURCE_LOCATION (decl);
+ iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
start_mangling (decl);
pop_tinst_level ();
current_function_decl = saved_fn;
}
- input_location = saved_loc;
return result;
}
static void
perform_typedefs_access_check (tree tmpl, tree targs)
{
- location_t saved_location;
unsigned i;
qualified_typedef_usage_t *iter;
&& 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;
/* 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