cp-tree.h (class iloc_sentinel): New.

* 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
This commit is contained in:
Jason Merrill 2019-09-27 14:19:55 -04:00 committed by Jason Merrill
parent 975d043ff6
commit c872f1506d
5 changed files with 32 additions and 17 deletions

View 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

View 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. */

View 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)
{

View 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;
}

View 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