Skip to content

Commit

Permalink
Merge of 6177b45
Browse files Browse the repository at this point in the history
  • Loading branch information
sys-ceuplift committed Nov 5, 2024
2 parents c15d8bf + 6177b45 commit 8707472
Show file tree
Hide file tree
Showing 13 changed files with 413 additions and 6 deletions.
57 changes: 54 additions & 3 deletions gcc/cp/module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11585,8 +11585,6 @@ trees_in::is_matching_decl (tree existing, tree decl, bool is_typedef)

if (!same_type_p (TREE_VALUE (d_args), TREE_VALUE (e_args)))
goto mismatch;

// FIXME: Check default values
}

/* If EXISTING has an undeduced or uninstantiated exception
Expand Down Expand Up @@ -11725,7 +11723,60 @@ trees_in::is_matching_decl (tree existing, tree decl, bool is_typedef)
if (!DECL_EXTERNAL (d_inner))
DECL_EXTERNAL (e_inner) = false;

// FIXME: Check default tmpl and fn parms here
if (TREE_CODE (decl) == TEMPLATE_DECL)
{
/* Merge default template arguments. */
tree d_parms = DECL_INNERMOST_TEMPLATE_PARMS (decl);
tree e_parms = DECL_INNERMOST_TEMPLATE_PARMS (existing);
gcc_checking_assert (TREE_VEC_LENGTH (d_parms)
== TREE_VEC_LENGTH (e_parms));
for (int i = 0; i < TREE_VEC_LENGTH (d_parms); ++i)
{
tree d_default = TREE_PURPOSE (TREE_VEC_ELT (d_parms, i));
tree& e_default = TREE_PURPOSE (TREE_VEC_ELT (e_parms, i));
if (e_default == NULL_TREE)
e_default = d_default;
else if (d_default != NULL_TREE
&& !cp_tree_equal (d_default, e_default))
{
auto_diagnostic_group d;
tree d_parm = TREE_VALUE (TREE_VEC_ELT (d_parms, i));
tree e_parm = TREE_VALUE (TREE_VEC_ELT (e_parms, i));
error_at (DECL_SOURCE_LOCATION (d_parm),
"conflicting default argument for %#qD", d_parm);
inform (DECL_SOURCE_LOCATION (e_parm),
"existing default declared here");
return false;
}
}
}

if (TREE_CODE (d_inner) == FUNCTION_DECL)
{
/* Merge default function arguments. */
tree d_parm = FUNCTION_FIRST_USER_PARMTYPE (d_inner);
tree e_parm = FUNCTION_FIRST_USER_PARMTYPE (e_inner);
int i = 0;
for (; d_parm && d_parm != void_list_node;
d_parm = TREE_CHAIN (d_parm), e_parm = TREE_CHAIN (e_parm), ++i)
{
tree d_default = TREE_PURPOSE (d_parm);
tree& e_default = TREE_PURPOSE (e_parm);
if (e_default == NULL_TREE)
e_default = d_default;
else if (d_default != NULL_TREE
&& !cp_tree_equal (d_default, e_default))
{
auto_diagnostic_group d;
error_at (get_fndecl_argument_location (d_inner, i),
"conflicting default argument for parameter %P of %#qD",
i, decl);
inform (get_fndecl_argument_location (e_inner, i),
"existing default declared here");
return false;
}
}
}

return true;
}
Expand Down
33 changes: 33 additions & 0 deletions gcc/cp/tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4042,6 +4042,39 @@ cp_tree_equal (tree t1, tree t2)
TARGET_EXPR_INITIAL (t2));
}

case AGGR_INIT_EXPR:
{
int n = aggr_init_expr_nargs (t1);
if (n != aggr_init_expr_nargs (t2))
return false;

if (!cp_tree_equal (AGGR_INIT_EXPR_FN (t1),
AGGR_INIT_EXPR_FN (t2)))
return false;

tree o1 = AGGR_INIT_EXPR_SLOT (t1);
tree o2 = AGGR_INIT_EXPR_SLOT (t2);

/* Similarly to TARGET_EXPRs, if the VAR_DECL is unallocated we're
going to unify the initialization, so treat it as equivalent
to anything. */
if (VAR_P (o1) && DECL_NAME (o1) == NULL_TREE
&& !DECL_RTL_SET_P (o1))
/*Nop*/;
else if (VAR_P (o2) && DECL_NAME (o2) == NULL_TREE
&& !DECL_RTL_SET_P (o2))
/*Nop*/;
else if (!cp_tree_equal (o1, o2))
return false;

for (int i = 0; i < n; ++i)
if (!cp_tree_equal (AGGR_INIT_EXPR_ARG (t1, i),
AGGR_INIT_EXPR_ARG (t2, i)))
return false;

return true;
}

case PARM_DECL:
/* For comparing uses of parameters in late-specified return types
with an out-of-class definition of the function, but can also come
Expand Down
Loading

0 comments on commit 8707472

Please sign in to comment.