aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/method.c
diff options
context:
space:
mode:
authorVille Voutilainen <ville.voutilainen@gmail.com>2017-05-17 16:54:23 +0300
committerVille Voutilainen <ville@gcc.gnu.org>2017-05-17 16:54:23 +0300
commitb42cc3ca244ea57d5112638a73e7f83c58202a84 (patch)
tree5dba2cc1db7a08d1f9a5a4c2c53436d4d65bed2e /gcc/cp/method.c
parent36f4bc9ce82363820ce3aac4bb3f7fbfdeef1663 (diff)
downloadgcc-b42cc3ca244ea57d5112638a73e7f83c58202a84.zip
gcc-b42cc3ca244ea57d5112638a73e7f83c58202a84.tar.gz
gcc-b42cc3ca244ea57d5112638a73e7f83c58202a84.tar.bz2
Implement new C++ intrinsics __is_assignable and __is_constructible.
c-family/ Implement new C++ intrinsics __is_assignable and __is_constructible. * c-common.c (__is_assignable, __is_constructible): New. * c-common.h (RID_IS_ASSIGNABLE, RID_IS_CONSTRUCTIBLE): Likewise. cp/ PR c++/80654 PR c++/80682 Implement new C++ intrinsics __is_assignable and __is_constructible. * cp-tree.h (CPTK_IS_ASSIGNABLE, CPTK_IS_CONSTRUCTIBLE): New. (is_xible): New. * cxx-pretty-print.c (pp_cxx_trait_expression): Handle CPTK_IS_ASSIGNABLE and CPTK_IS_CONSTRUCTIBLE. * method.c (constructible_expr): Set cp_unevaluated. (is_xible_helper): New. (is_trivially_xible): Adjust. (is_xible): New. * parser.c (cp_parser_primary_expression): Handle RID_IS_ASSIGNABLE and RID_IS_CONSTRUCTIBLE. (cp_parser_trait_expr): Likewise. * semantics.c (trait_expr_value): Handle CPTK_IS_ASSIGNABLE and CPTK_IS_CONSTRUCTIBLE. testsuite/ * g++.dg/ext/80654.C: New. libstdc++-v3/ Implement new C++ intrinsics __is_assignable and __is_constructible. * include/std/type_traits (__do_is_static_castable_impl): Remove. (__is_static_castable_impl, __is_static_castable_safe): Likewise. (__is_static_castable, __do_is_direct_constructible_impl): Likewise. (__is_direct_constructible_impl): Likewise. (__is_direct_constructible_new_safe): Likewise. (__is_base_to_derived_ref, __is_lvalue_to_rvalue_ref): Likewise. (__is_direct_constructible_ref_cast): Likewise. (__is_direct_constructible_new, __is_direct_constructible): Likewise. (__do_is_nary_constructible_impl): Likewise. (__is_nary_constructible_impl, __is_nary_constructible): Likewise. (__is_constructible_impl): Likewise. (is_constructible): Call the intrinsic. (__is_assignable_helper): Remove. (is_assignable): Call the intrinsic. (is_trivially_constructible): Likewise. (__is_trivially_copy_constructible_impl): New. (is_trivially_copy_constructible): Use it. (__is_trivially_move_constructible_impl): New. (is_trivially_move_constructible): Use it. (is_trivially_assignable): Call the intrinsic. (__is_trivially_copy_assignable_impl): New. (is_trivially_copy_assignable): Use it. (__is_trivially_move_assignable_impl): New. (is_trivially_move_assignable): Use it. (testsuite/20_util/declval/requirements/1_neg.cc): Adjust. (testsuite/20_util/is_trivially_copy_assignable/value.cc): Add test for void. (testsuite/20_util/is_trivially_copy_constructible/value.cc): Likewise. (testsuite/20_util/is_trivially_move_assignable/value.cc): Likewise. (testsuite/20_util/is_trivially_move_constructible/value.cc): Likewise. (testsuite/20_util/make_signed/requirements/typedefs_neg.cc): Adjust. (testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc): Likewise. From-SVN: r248153
Diffstat (limited to 'gcc/cp/method.c')
-rw-r--r--gcc/cp/method.c42
1 files changed, 35 insertions, 7 deletions
diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index 9898ff1..756b59d 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -1162,6 +1162,7 @@ constructible_expr (tree to, tree from)
{
tree ctype = to;
vec<tree, va_gc> *args = NULL;
+ cp_unevaluated cp_uneval_guard;
if (TREE_CODE (to) != REFERENCE_TYPE)
to = cp_build_reference_type (to, /*rval*/false);
tree ob = build_stub_object (to);
@@ -1198,22 +1199,36 @@ constructible_expr (tree to, tree from)
return expr;
}
-/* Returns true iff TO is trivially assignable (if CODE is MODIFY_EXPR) or
+/* Returns a tree 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. */
-bool
-is_trivially_xible (enum tree_code code, tree to, tree from)
+static tree
+is_xible_helper (enum tree_code code, tree to, tree from, bool trivial)
{
- if (VOID_TYPE_P (to))
- return false;
+ if (VOID_TYPE_P (to) || ABSTRACT_CLASS_TYPE_P (to)
+ || (from && FUNC_OR_METHOD_TYPE_P (from)
+ && (TYPE_READONLY (from) || FUNCTION_REF_QUALIFIED (from))))
+ return error_mark_node;
tree expr;
if (code == MODIFY_EXPR)
expr = assignable_expr (to, from);
- else if (from && TREE_CHAIN (from))
- return false; // only 0- and 1-argument ctors can be trivial
+ else if (trivial && from && TREE_CHAIN (from))
+ return error_mark_node; // only 0- and 1-argument ctors can be trivial
else
expr = constructible_expr (to, from);
+ return expr;
+}
+
+/* Returns true iff TO is trivially 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_trivially_xible (enum tree_code code, tree to, tree from)
+{
+ tree expr;
+ expr = is_xible_helper (code, to, from, /*trivial*/true);
if (expr == error_mark_node)
return false;
@@ -1221,6 +1236,19 @@ is_trivially_xible (enum tree_code code, tree to, tree from)
return !nt;
}
+/* 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. */
+
+bool
+is_xible (enum tree_code code, tree to, tree from)
+{
+ tree expr = is_xible_helper (code, to, from, /*trivial*/false);
+ if (expr == error_mark_node)
+ return false;
+ return !!expr;
+}
+
/* Subroutine of synthesized_method_walk. Update SPEC_P, TRIVIAL_P and
DELETED_P or give an error message MSG with argument ARG. */