forked from Imagelibrary/binutils-gdb
Port c++/78252 from GCC
PR c++/78252 * cp-demangle.c (struct d_print_info): Add is_lambda_arg field. (d_print_init): Initialize it. (d_print_comp_inner) <DEMANGLE_COMPONENT_TEMPLATE_PARAM>: Check is_lambda_arg for auto. <DEMANGLE_COMPONENT_REFERENCE, DEMANGLE_COMPONENT_RVALUE_REFERENCE>: Skip smashing check when is_lambda_arg. <DEMANGLE_COMPONENT_LAMBDA>: Increment is_lambda_arg around arg printing. * testsuite/demangle-expected: Add lambda auto mangling cases.
This commit is contained in:
@@ -343,6 +343,9 @@ struct d_print_info
|
||||
struct d_print_mod *modifiers;
|
||||
/* Set to 1 if we saw a demangling error. */
|
||||
int demangle_failure;
|
||||
/* Non-zero if we're printing a lambda argument. A template
|
||||
parameter reference actually means 'auto'. */
|
||||
int is_lambda_arg;
|
||||
/* The current index into any template argument packs we are using
|
||||
for printing, or -1 to print the whole pack. */
|
||||
int pack_index;
|
||||
@@ -4126,6 +4129,7 @@ d_print_init (struct d_print_info *dpi, demangle_callbackref callback,
|
||||
dpi->opaque = opaque;
|
||||
|
||||
dpi->demangle_failure = 0;
|
||||
dpi->is_lambda_arg = 0;
|
||||
|
||||
dpi->component_stack = NULL;
|
||||
|
||||
@@ -4783,33 +4787,41 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
|
||||
}
|
||||
|
||||
case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
|
||||
{
|
||||
struct d_print_template *hold_dpt;
|
||||
struct demangle_component *a = d_lookup_template_argument (dpi, dc);
|
||||
if (dpi->is_lambda_arg)
|
||||
{
|
||||
/* Show the template parm index, as that's how g++ displays
|
||||
these, and future proofs us against potential
|
||||
'[]<typename T> (T *a, T *b) {...}'. */
|
||||
d_append_buffer (dpi, "auto:", 5);
|
||||
d_append_num (dpi, dc->u.s_number.number + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
struct d_print_template *hold_dpt;
|
||||
struct demangle_component *a = d_lookup_template_argument (dpi, dc);
|
||||
|
||||
if (a && a->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST)
|
||||
a = d_index_template_argument (a, dpi->pack_index);
|
||||
if (a && a->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST)
|
||||
a = d_index_template_argument (a, dpi->pack_index);
|
||||
|
||||
if (a == NULL)
|
||||
{
|
||||
d_print_error (dpi);
|
||||
return;
|
||||
}
|
||||
if (a == NULL)
|
||||
{
|
||||
d_print_error (dpi);
|
||||
return;
|
||||
}
|
||||
|
||||
/* While processing this parameter, we need to pop the list of
|
||||
templates. This is because the template parameter may
|
||||
itself be a reference to a parameter of an outer
|
||||
template. */
|
||||
/* While processing this parameter, we need to pop the list
|
||||
of templates. This is because the template parameter may
|
||||
itself be a reference to a parameter of an outer
|
||||
template. */
|
||||
|
||||
hold_dpt = dpi->templates;
|
||||
dpi->templates = hold_dpt->next;
|
||||
hold_dpt = dpi->templates;
|
||||
dpi->templates = hold_dpt->next;
|
||||
|
||||
d_print_comp (dpi, options, a);
|
||||
d_print_comp (dpi, options, a);
|
||||
|
||||
dpi->templates = hold_dpt;
|
||||
|
||||
return;
|
||||
}
|
||||
dpi->templates = hold_dpt;
|
||||
}
|
||||
return;
|
||||
|
||||
case DEMANGLE_COMPONENT_CTOR:
|
||||
d_print_comp (dpi, options, dc->u.s_ctor.name);
|
||||
@@ -4946,7 +4958,8 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
|
||||
{
|
||||
/* Handle reference smashing: & + && = &. */
|
||||
const struct demangle_component *sub = d_left (dc);
|
||||
if (sub->type == DEMANGLE_COMPONENT_TEMPLATE_PARAM)
|
||||
if (!dpi->is_lambda_arg
|
||||
&& sub->type == DEMANGLE_COMPONENT_TEMPLATE_PARAM)
|
||||
{
|
||||
struct d_saved_scope *scope = d_get_saved_scope (dpi, sub);
|
||||
struct demangle_component *a;
|
||||
@@ -5616,7 +5629,11 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
|
||||
|
||||
case DEMANGLE_COMPONENT_LAMBDA:
|
||||
d_append_string (dpi, "{lambda(");
|
||||
/* Generic lambda auto parms are mangled as the template type
|
||||
parm they are. */
|
||||
dpi->is_lambda_arg++;
|
||||
d_print_comp (dpi, options, dc->u.s_unary_num.sub);
|
||||
dpi->is_lambda_arg--;
|
||||
d_append_string (dpi, ")#");
|
||||
d_append_num (dpi, dc->u.s_unary_num.num + 1);
|
||||
d_append_char (dpi, '}');
|
||||
|
||||
Reference in New Issue
Block a user