aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/pt.cc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2022-09-29 09:18:11 -0400
committerPatrick Palka <ppalka@redhat.com>2022-09-29 09:18:11 -0400
commit817e878a31671fcb68492bce35aa1ac87e08efdb (patch)
tree12b20c83ddd71f33a87747f21776d27673da7295 /gcc/cp/pt.cc
parentdf7f2736509cfe5e1dd7d9f263355c5043347a9c (diff)
downloadgcc-817e878a31671fcb68492bce35aa1ac87e08efdb.zip
gcc-817e878a31671fcb68492bce35aa1ac87e08efdb.tar.gz
gcc-817e878a31671fcb68492bce35aa1ac87e08efdb.tar.bz2
c++: introduce TRAIT_TYPE alongside TRAIT_EXPR
We already have generic support for predicate-like traits that yield a boolean value via TRAIT_EXPR, but we lack the same support for traits that yield a type instead of a value. Such support would streamline implementing efficient builtins for the standard library type traits. To that end this patch implements a generic TRAIT_TYPE type alongside TRAIT_EXPR, and reimplements the existing UNDERLYING_TYPE builtin trait using this new TRAIT_TYPE. gcc/cp/ChangeLog: * cp-objcp-common.cc (cp_common_init_ts): Replace UNDERLYING_TYPE with TRAIT_TYPE. * cp-tree.def (TRAIT_TYPE): Define. (UNDERLYING_TYPE): Remove. * cp-tree.h (TRAIT_TYPE_KIND_RAW): Define. (TRAIT_TYPE_KIND): Define. (TRAIT_TYPE_TYPE1): Define. (TRAIT_TYPE_TYPE2): Define. (WILDCARD_TYPE_P): Return true for TRAIT_TYPE. (finish_trait_type): Declare. * cxx-pretty-print.cc (cxx_pretty_printer::primary_expression): Adjust after renaming pp_cxx_trait_expression. (cxx_pretty_printer::simple_type_specifier) <case TRAIT_TYPE>: New. (cxx_pretty_printer::type_id): Replace UNDERLYING_TYPE with TRAIT_TYPE. (pp_cxx_trait_expression): Rename to ... (pp_cxx_trait): ... this. Handle TRAIT_TYPE as well. Correct pretty printing of the trailing arguments. * cxx-pretty-print.h (pp_cxx_trait_expression): Rename to ... (pp_cxx_trait_type): ... this. * error.cc (dump_type) <case UNDERLYING_TYPE>: Remove. <case TRAIT_TYPE>: New. (dump_type_prefix): Replace UNDERLYING_WITH with TRAIT_TYPE. (dump_type_suffix): Likewise. * mangle.cc (write_type) <case UNDERLYING_TYPE>: Remove. <case TRAIT_TYPE>: New. * module.cc (trees_out::type_node) <case UNDERLYING_TYPE>: Remove. <case TRAIT_TYPE>: New. (trees_in::tree_node): Likewise. * parser.cc (cp_parser_primary_expression): Adjust after renaming cp_parser_trait_expr. (cp_parser_trait_expr): Rename to ... (cp_parser_trait): ... this. Call finish_trait_type for traits that yield a type. (cp_parser_simple_type_specifier): Adjust after renaming cp_parser_trait_expr. * pt.cc (for_each_template_parm_r) <case UNDERLYING_TYPE>: Remove. <case TRAIT_TYPE>: New. (tsubst): Likewise. (unify): Replace UNDERLYING_TYPE with TRAIT_TYPE. (dependent_type_p_r): Likewise. * semantics.cc (finish_underlying_type): Don't return UNDERLYING_TYPE anymore when processing_template_decl. (finish_trait_type): Define. * tree.cc (strip_typedefs) <case UNDERLYING_TYPE>: Remove. <case TRAIT_TYPE>: New. (cp_walk_subtrees): Likewise. * typeck.cc (structural_comptypes): Likewise. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/alias-decl-59.C: Adjust expected error message. * g++.dg/ext/underlying_type7.C: Likewise. * g++.dg/ext/underlying_type13.C: New test. * g++.dg/ext/underlying_type14.C: New test.
Diffstat (limited to 'gcc/cp/pt.cc')
-rw-r--r--gcc/cp/pt.cc29
1 files changed, 20 insertions, 9 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index c7adaef..0f92374 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -10617,7 +10617,6 @@ for_each_template_parm_r (tree *tp, int *walk_subtrees, void *d)
case TYPEOF_TYPE:
case DECLTYPE_TYPE:
- case UNDERLYING_TYPE:
if (pfd->include_nondeduced_p
&& for_each_template_parm (TYPE_VALUES_RAW (t), fn, data,
pfd->visited,
@@ -10627,6 +10626,15 @@ for_each_template_parm_r (tree *tp, int *walk_subtrees, void *d)
*walk_subtrees = false;
break;
+ case TRAIT_TYPE:
+ if (pfd->include_nondeduced_p)
+ {
+ WALK_SUBTREE (TRAIT_TYPE_TYPE1 (t));
+ WALK_SUBTREE (TRAIT_TYPE_TYPE2 (t));
+ }
+ *walk_subtrees = false;
+ break;
+
case FUNCTION_DECL:
case VAR_DECL:
if (DECL_LANG_SPECIFIC (t) && DECL_TEMPLATE_INFO (t))
@@ -16513,11 +16521,14 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
complain | tf_ignore_bad_quals);
}
- case UNDERLYING_TYPE:
+ case TRAIT_TYPE:
{
- tree type = tsubst (UNDERLYING_TYPE_TYPE (t), args,
- complain, in_decl);
- return finish_underlying_type (type);
+ tree type1 = tsubst (TRAIT_TYPE_TYPE1 (t), args, complain, in_decl);
+ tree type2 = tsubst (TRAIT_TYPE_TYPE2 (t), args, complain, in_decl);
+ type = finish_trait_type (TRAIT_TYPE_KIND (t), type1, type2);
+ return cp_build_qualified_type (type,
+ cp_type_quals (t) | cp_type_quals (type),
+ complain | tf_ignore_bad_quals);
}
case TYPE_ARGUMENT_PACK:
@@ -24927,9 +24938,9 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
case TYPEOF_TYPE:
case DECLTYPE_TYPE:
- case UNDERLYING_TYPE:
+ case TRAIT_TYPE:
/* Cannot deduce anything from TYPEOF_TYPE, DECLTYPE_TYPE,
- or UNDERLYING_TYPE nodes. */
+ or TRAIT_TYPE nodes. */
return unify_success (explain_p);
case ERROR_MARK:
@@ -27504,12 +27515,12 @@ dependent_type_p_r (tree type)
(INNERMOST_TEMPLATE_ARGS (CLASSTYPE_TI_ARGS (type)))))
return true;
- /* All TYPEOF_TYPEs, DECLTYPE_TYPEs, and UNDERLYING_TYPEs are
+ /* All TYPEOF_TYPEs, DECLTYPE_TYPEs, and TRAIT_TYPEs are
dependent; if the argument of the `typeof' expression is not
type-dependent, then it should already been have resolved. */
if (TREE_CODE (type) == TYPEOF_TYPE
|| TREE_CODE (type) == DECLTYPE_TYPE
- || TREE_CODE (type) == UNDERLYING_TYPE)
+ || TREE_CODE (type) == TRAIT_TYPE)
return true;
/* A template argument pack is dependent if any of its packed