diff options
author | Ville Voutilainen <ville.voutilainen@gmail.com> | 2020-10-26 15:36:24 +0200 |
---|---|---|
committer | Ville Voutilainen <ville.voutilainen@gmail.com> | 2020-10-26 15:36:24 +0200 |
commit | 9e2256dcd481ffe3a8c79b65eba19fbb14b7ff8d (patch) | |
tree | 3529c16b86b6fca18f65c782508ea6af9d01ec38 /gcc/cp | |
parent | 783dc02d89712f5219093d33ad7f08e1509a2134 (diff) | |
download | gcc-9e2256dcd481ffe3a8c79b65eba19fbb14b7ff8d.zip gcc-9e2256dcd481ffe3a8c79b65eba19fbb14b7ff8d.tar.gz gcc-9e2256dcd481ffe3a8c79b65eba19fbb14b7ff8d.tar.bz2 |
c++: Implement __is_nothrow_constructible and __is_nothrow_assignable
gcc/c-family/ChangeLog:
* c-common.c (__is_nothrow_assignable): New.
(__is_nothrow_constructible): Likewise.
* c-common.h (RID_IS_NOTHROW_ASSIGNABLE): New.
(RID_IS_NOTHROW_CONSTRUCTIBLE): Likewise.
gcc/cp/ChangeLog:
* cp-tree.h (CPTK_IS_NOTHROW_ASSIGNABLE): New.
(CPTK_IS_NOTHROW_CONSTRUCTIBLE): Likewise.
(is_nothrow_xible): Likewise.
* method.c (is_nothrow_xible): New.
(is_trivially_xible): Tweak.
* parser.c (cp_parser_primary_expression): Handle the new RID_*.
(cp_parser_trait_expr): Likewise.
* semantics.c (trait_expr_value): Handle the new RID_*.
(finish_trait_expr): Likewise.
libstdc++-v3/ChangeLog:
* include/std/type_traits (__is_nt_constructible_impl): Remove.
(__is_nothrow_constructible_impl): Adjust.
(is_nothrow_default_constructible): Likewise.
(__is_nt_assignable_impl): Remove.
(__is_nothrow_assignable_impl): Adjust.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/cp-tree.h | 5 | ||||
-rw-r--r-- | gcc/cp/method.c | 17 | ||||
-rw-r--r-- | gcc/cp/parser.c | 10 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 8 |
4 files changed, 36 insertions, 4 deletions
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 5c06ac3..1ce2098 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -1323,7 +1323,9 @@ enum cp_trait_kind CPTK_IS_UNION, CPTK_UNDERLYING_TYPE, CPTK_IS_ASSIGNABLE, - CPTK_IS_CONSTRUCTIBLE + CPTK_IS_CONSTRUCTIBLE, + CPTK_IS_NOTHROW_ASSIGNABLE, + CPTK_IS_NOTHROW_CONSTRUCTIBLE }; /* The types that we are processing. */ @@ -6752,6 +6754,7 @@ extern void use_thunk (tree, bool); extern bool trivial_fn_p (tree); extern tree forward_parm (tree); extern bool is_trivially_xible (enum tree_code, tree, tree); +extern bool is_nothrow_xible (enum tree_code, tree, tree); extern bool is_xible (enum tree_code, tree, tree); extern tree get_defaulted_eh_spec (tree, tsubst_flags_t = tf_warning_or_error); extern bool maybe_explain_implicit_delete (tree); diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 6e4c5f7..16e7635 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -1924,15 +1924,26 @@ is_xible_helper (enum tree_code code, tree to, tree from, bool trivial) bool is_trivially_xible (enum tree_code code, tree to, tree from) { - tree expr; - expr = is_xible_helper (code, to, from, /*trivial*/true); - + tree expr = is_xible_helper (code, to, from, /*trivial*/true); if (expr == NULL_TREE || expr == error_mark_node) return false; tree nt = cp_walk_tree_without_duplicates (&expr, check_nontriv, NULL); return !nt; } +/* Returns true iff TO is nothrow assignable (if CODE is MODIFY_EXPR) or + constructible (otherwise) from FROM, which is a single type for + assignment or a list of types for construction. */ + +bool +is_nothrow_xible (enum tree_code code, tree to, tree from) +{ + tree expr = is_xible_helper (code, to, from, /*trivial*/false); + if (expr == NULL_TREE || expr == error_mark_node) + return false; + return expr_noexcept_p (expr, tf_none); +} + /* Returns true iff TO is assignable (if CODE is MODIFY_EXPR) or constructible (otherwise) from FROM, which is a single type for assignment or a list of types for construction. */ diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 7ec7d42..cce3d0a 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -5637,6 +5637,8 @@ cp_parser_primary_expression (cp_parser *parser, case RID_IS_UNION: case RID_IS_ASSIGNABLE: case RID_IS_CONSTRUCTIBLE: + case RID_IS_NOTHROW_ASSIGNABLE: + case RID_IS_NOTHROW_CONSTRUCTIBLE: return cp_parser_trait_expr (parser, token->keyword); // C++ concepts @@ -10501,6 +10503,14 @@ cp_parser_trait_expr (cp_parser* parser, enum rid keyword) kind = CPTK_IS_CONSTRUCTIBLE; variadic = true; break; + case RID_IS_NOTHROW_ASSIGNABLE: + kind = CPTK_IS_NOTHROW_ASSIGNABLE; + binary = true; + break; + case RID_IS_NOTHROW_CONSTRUCTIBLE: + kind = CPTK_IS_NOTHROW_CONSTRUCTIBLE; + variadic = true; + break; default: gcc_unreachable (); } diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 1e42cd7..ac48847 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -10133,6 +10133,12 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CONSTRUCTIBLE: return is_xible (INIT_EXPR, type1, type2); + case CPTK_IS_NOTHROW_ASSIGNABLE: + return is_nothrow_xible (MODIFY_EXPR, type1, type2); + + case CPTK_IS_NOTHROW_CONSTRUCTIBLE: + return is_nothrow_xible (INIT_EXPR, type1, type2); + default: gcc_unreachable (); return false; @@ -10213,6 +10219,8 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_TRIVIALLY_ASSIGNABLE: case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: + case CPTK_IS_NOTHROW_ASSIGNABLE: + case CPTK_IS_NOTHROW_CONSTRUCTIBLE: if (!check_trait_type (type1) || !check_trait_type (type2)) return error_mark_node; |