aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/method.cc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2023-04-20 15:00:06 -0400
committerPatrick Palka <ppalka@redhat.com>2023-04-20 15:00:06 -0400
commit76fa66ea397cb255ab1d68a90ff6b878236e9620 (patch)
tree795c8642211cb1ac46c5fa5fdd5e421ea710fd3a /gcc/cp/method.cc
parentd180a5524ccdab8ef839ee55efecf60ce5b0240b (diff)
downloadgcc-76fa66ea397cb255ab1d68a90ff6b878236e9620.zip
gcc-76fa66ea397cb255ab1d68a90ff6b878236e9620.tar.gz
gcc-76fa66ea397cb255ab1d68a90ff6b878236e9620.tar.bz2
c++: use TREE_VEC for trailing args of variadic built-in traits
This patch makes us use TREE_VEC instead of TREE_LIST to represent the trailing arguments of a variadic built-in trait. These built-ins are typically passed a simple pack expansion as the second argument, e.g. __is_constructible(T, Ts...) and the main benefit of this representation change is that substituting into this argument list is now basically free since tsubst_template_args makes sure we reuse the TREE_VEC of the corresponding ARGUMENT_PACK when expanding such a pack expansion. In the previous TREE_LIST representation we would need need to convert the expanded pack expansion into a TREE_LIST (via tsubst_tree_list). Note that an empty set of trailing arguments is now represented as an empty TREE_VEC instead of NULL_TREE, so now TRAIT_TYPE/EXPR_TYPE2 will be empty only for unary traits. gcc/cp/ChangeLog: * constraint.cc (diagnose_trait_expr): Convert a TREE_VEC of arguments into a TREE_LIST for sake of pretty printing. * cxx-pretty-print.cc (pp_cxx_trait): Handle TREE_VEC instead of TREE_LIST of trailing variadic trait arguments. * method.cc (constructible_expr): Likewise. (is_xible_helper): Likewise. * parser.cc (cp_parser_trait): Represent trailing variadic trait arguments as a TREE_VEC instead of TREE_LIST. * pt.cc (value_dependent_expression_p): Handle TREE_VEC instead of TREE_LIST of trailing variadic trait arguments. * semantics.cc (finish_type_pack_element): Likewise. (check_trait_type): Likewise.
Diffstat (limited to 'gcc/cp/method.cc')
-rw-r--r--gcc/cp/method.cc17
1 files changed, 9 insertions, 8 deletions
diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc
index 225ec45..00eae56 100644
--- a/gcc/cp/method.cc
+++ b/gcc/cp/method.cc
@@ -2075,8 +2075,9 @@ constructible_expr (tree to, tree from)
if (!TYPE_REF_P (to))
to = cp_build_reference_type (to, /*rval*/false);
tree ob = build_stub_object (to);
- for (; from; from = TREE_CHAIN (from))
- vec_safe_push (args, build_stub_object (TREE_VALUE (from)));
+ vec_alloc (args, TREE_VEC_LENGTH (from));
+ for (tree arg : tree_vec_range (from))
+ args->quick_push (build_stub_object (arg));
expr = build_special_member_call (ob, complete_ctor_identifier, &args,
ctype, LOOKUP_NORMAL, tf_none);
if (expr == error_mark_node)
@@ -2096,9 +2097,9 @@ constructible_expr (tree to, tree from)
}
else
{
- if (from == NULL_TREE)
+ const int len = TREE_VEC_LENGTH (from);
+ if (len == 0)
return build_value_init (strip_array_types (to), tf_none);
- const int len = list_length (from);
if (len > 1)
{
if (cxx_dialect < cxx20)
@@ -2112,9 +2113,9 @@ constructible_expr (tree to, tree from)
should be true. */
vec<constructor_elt, va_gc> *v;
vec_alloc (v, len);
- for (tree t = from; t; t = TREE_CHAIN (t))
+ for (tree arg : tree_vec_range (from))
{
- tree stub = build_stub_object (TREE_VALUE (t));
+ tree stub = build_stub_object (arg);
constructor_elt elt = { NULL_TREE, stub };
v->quick_push (elt);
}
@@ -2123,7 +2124,7 @@ constructible_expr (tree to, tree from)
CONSTRUCTOR_IS_PAREN_INIT (from) = true;
}
else
- from = build_stub_object (TREE_VALUE (from));
+ from = build_stub_object (TREE_VEC_ELT (from, 0));
expr = perform_direct_initialization_if_possible (to, from,
/*cast*/false,
tf_none);
@@ -2160,7 +2161,7 @@ is_xible_helper (enum tree_code code, tree to, tree from, bool trivial)
tree expr;
if (code == MODIFY_EXPR)
expr = assignable_expr (to, from);
- else if (trivial && from && TREE_CHAIN (from)
+ else if (trivial && TREE_VEC_LENGTH (from) > 1
&& cxx_dialect < cxx20)
return error_mark_node; // only 0- and 1-argument ctors can be trivial
// before C++20 aggregate paren init