aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2022-09-29 09:18:40 -0400
committerPatrick Palka <ppalka@redhat.com>2022-09-29 09:18:40 -0400
commit9ca147154074a0de548138b4e73477e94903a855 (patch)
tree689d3428db5ceea4aa86f800a8d59a1c8e9d300c /gcc/cp
parent817e878a31671fcb68492bce35aa1ac87e08efdb (diff)
downloadgcc-9ca147154074a0de548138b4e73477e94903a855.zip
gcc-9ca147154074a0de548138b4e73477e94903a855.tar.gz
gcc-9ca147154074a0de548138b4e73477e94903a855.tar.bz2
c++: implement __remove_cv, __remove_reference and __remove_cvref
This implements builtins for std::remove_cv, std::remove_reference and std::remove_cvref using TRAIT_TYPE from the previous patch. gcc/c-family/ChangeLog: * c-common.cc (c_common_reswords): Add __remove_cv, __remove_reference and __remove_cvref. * c-common.h (enum rid): Add RID_REMOVE_CV, RID_REMOVE_REFERENCE and RID_REMOVE_CVREF. gcc/cp/ChangeLog: * constraint.cc (diagnose_trait_expr): Handle CPTK_REMOVE_CV, CPTK_REMOVE_REFERENCE and CPTK_REMOVE_CVREF. * cp-objcp-common.cc (names_builtin_p): Likewise. * cp-tree.h (enum cp_trait_kind): Add CPTK_REMOVE_CV, CPTK_REMOVE_REFERENCE and CPTK_REMOVE_CVREF. * cxx-pretty-print.cc (pp_cxx_trait): Handle CPTK_REMOVE_CV, CPTK_REMOVE_REFERENCE and CPTK_REMOVE_CVREF. * parser.cc (cp_keyword_starts_decl_specifier_p): Return true for RID_REMOVE_CV, RID_REMOVE_REFERENCE and RID_REMOVE_CVREF. (cp_parser_trait): Handle RID_REMOVE_CV, RID_REMOVE_REFERENCE and RID_REMOVE_CVREF. (cp_parser_simple_type_specifier): Likewise. * semantics.cc (finish_trait_type): Likewise. libstdc++-v3/ChangeLog: * include/bits/unique_ptr.h (unique_ptr<_Tp[], _Dp>): Remove __remove_cv and use __remove_cv_t instead. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __remove_cv, __remove_reference and __remove_cvref. * g++.dg/ext/remove_cv.C: New test. * g++.dg/ext/remove_reference.C: New test. * g++.dg/ext/remove_cvref.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/constraint.cc3
-rw-r--r--gcc/cp/cp-objcp-common.cc3
-rw-r--r--gcc/cp/cp-tree.h5
-rw-r--r--gcc/cp/cxx-pretty-print.cc9
-rw-r--r--gcc/cp/parser.cc18
-rw-r--r--gcc/cp/semantics.cc10
6 files changed, 47 insertions, 1 deletions
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 266ec58..ca73aff 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -3714,6 +3714,9 @@ diagnose_trait_expr (tree expr, tree args)
case CPTK_BASES:
case CPTK_DIRECT_BASES:
case CPTK_UNDERLYING_TYPE:
+ case CPTK_REMOVE_CV:
+ case CPTK_REMOVE_REFERENCE:
+ case CPTK_REMOVE_CVREF:
/* We shouldn't see these non-expression traits. */
gcc_unreachable ();
/* We deliberately omit the default case so that when adding a new
diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc
index 380f288..2d3f206 100644
--- a/gcc/cp/cp-objcp-common.cc
+++ b/gcc/cp/cp-objcp-common.cc
@@ -467,6 +467,9 @@ names_builtin_p (const char *name)
case RID_IS_NOTHROW_CONVERTIBLE:
case RID_REF_CONSTRUCTS_FROM_TEMPORARY:
case RID_REF_CONVERTS_FROM_TEMPORARY:
+ case RID_REMOVE_CV:
+ case RID_REMOVE_REFERENCE:
+ case RID_REMOVE_CVREF:
return true;
default:
break;
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index ff9913c..3cbcdf7 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -1412,7 +1412,10 @@ enum cp_trait_kind
CPTK_IS_CONVERTIBLE,
CPTK_IS_NOTHROW_CONVERTIBLE,
CPTK_REF_CONSTRUCTS_FROM_TEMPORARY,
- CPTK_REF_CONVERTS_FROM_TEMPORARY
+ CPTK_REF_CONVERTS_FROM_TEMPORARY,
+ CPTK_REMOVE_CV,
+ CPTK_REMOVE_REFERENCE,
+ CPTK_REMOVE_CVREF,
};
/* The types that we are processing. */
diff --git a/gcc/cp/cxx-pretty-print.cc b/gcc/cp/cxx-pretty-print.cc
index 752ce3f..b916154 100644
--- a/gcc/cp/cxx-pretty-print.cc
+++ b/gcc/cp/cxx-pretty-print.cc
@@ -2728,6 +2728,15 @@ pp_cxx_trait (cxx_pretty_printer *pp, tree t)
case CPTK_UNDERLYING_TYPE:
pp_cxx_ws_string (pp, "__underlying_type");
break;
+ case CPTK_REMOVE_CV:
+ pp_cxx_ws_string (pp, "__remove_cv");
+ break;
+ case CPTK_REMOVE_REFERENCE:
+ pp_cxx_ws_string (pp, "__remove_reference");
+ break;
+ case CPTK_REMOVE_CVREF:
+ pp_cxx_ws_string (pp, "__remove_cvref");
+ break;
default:
gcc_unreachable ();
}
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 9f5e2c2..d592d78 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -1147,6 +1147,9 @@ cp_keyword_starts_decl_specifier_p (enum rid keyword)
/* C++11 extensions. */
case RID_DECLTYPE:
case RID_UNDERLYING_TYPE:
+ case RID_REMOVE_CV:
+ case RID_REMOVE_REFERENCE:
+ case RID_REMOVE_CVREF:
case RID_CONSTEXPR:
/* C++20 extensions. */
case RID_CONSTINIT:
@@ -11027,6 +11030,18 @@ cp_parser_trait (cp_parser* parser, enum rid keyword)
kind = CPTK_REF_CONVERTS_FROM_TEMPORARY;
binary = true;
break;
+ case RID_REMOVE_CV:
+ kind = CPTK_REMOVE_CV;
+ type = true;
+ break;
+ case RID_REMOVE_REFERENCE:
+ kind = CPTK_REMOVE_REFERENCE;
+ type = true;
+ break;
+ case RID_REMOVE_CVREF:
+ kind = CPTK_REMOVE_CVREF;
+ type = true;
+ break;
default:
gcc_unreachable ();
}
@@ -19867,6 +19882,9 @@ cp_parser_simple_type_specifier (cp_parser* parser,
return type;
case RID_UNDERLYING_TYPE:
+ case RID_REMOVE_CV:
+ case RID_REMOVE_REFERENCE:
+ case RID_REMOVE_CVREF:
type = cp_parser_trait (parser, token->keyword);
if (decl_specs)
cp_parser_set_decl_spec_type (decl_specs, type,
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index aae492d..66ee218 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12240,6 +12240,16 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2)
{
case CPTK_UNDERLYING_TYPE:
return finish_underlying_type (type1);
+ case CPTK_REMOVE_CV:
+ return cv_unqualified (type1);
+ case CPTK_REMOVE_REFERENCE:
+ if (TYPE_REF_P (type1))
+ type1 = TREE_TYPE (type1);
+ return type1;
+ case CPTK_REMOVE_CVREF:
+ if (TYPE_REF_P (type1))
+ type1 = TREE_TYPE (type1);
+ return cv_unqualified (type1);
default:
gcc_unreachable ();
}