From b29441ec7926c8c8bb789aab3860da6f02a35b80 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Wed, 25 Apr 2007 23:55:11 +0000 Subject: [PATCH] semantics.c (classtype_has_nothrow_copy_or_assign_p): Adjust per N2255; rename as classtype_has_nothrow_assign_or_copy_p. gcc/cp 2007-04-25 Paolo Carlini * semantics.c (classtype_has_nothrow_copy_or_assign_p): Adjust per N2255; rename as classtype_has_nothrow_assign_or_copy_p. (trait_expr_value): Adjust. gcc/testsuite/ 2007-04-25 Paolo Carlini * g++.dg/ext/has_nothrow_assign.C: Adjust per N2255. gcc/ 2007-04-25 Paolo Carlini * doc/extend.texi ([Type Traits]): Adjust per N2255. From-SVN: r124170 --- gcc/ChangeLog | 4 + gcc/cp/ChangeLog | 6 ++ gcc/cp/semantics.c | 80 +++++++------------ gcc/doc/extend.texi | 13 ++- gcc/testsuite/ChangeLog | 4 + gcc/testsuite/g++.dg/ext/has_nothrow_assign.C | 2 +- 6 files changed, 49 insertions(+), 60 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c4cfa5cbd21..d20eab51961 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2007-04-25 Paolo Carlini + + * doc/extend.texi ([Type Traits]): Adjust per N2255. + 2007-04-25 Bob Wilson * config/xtensa/lib1funcs.asm (__udivsi3, __divsi3): Throw an exception diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f3eb5debfd4..37b7742734e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2007-04-25 Paolo Carlini + + * semantics.c (classtype_has_nothrow_copy_or_assign_p): Adjust + per N2255; rename as classtype_has_nothrow_assign_or_copy_p. + (trait_expr_value): Adjust. + 2007-04-23 Simon Baldwin * decl.c (grokparms): Added new error for duplicate function diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index bfb84ec5d5f..c683ba298ff 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -4007,63 +4007,37 @@ finish_static_assert (tree condition, tree message, location_t location, } } -/* Called from trait_expr_value to evaluate either __has_nothrow_copy or - __has_nothrow_assign, depending on copy_p. */ +/* Called from trait_expr_value to evaluate either __has_nothrow_assign or + __has_nothrow_copy, depending on assign_p. */ static bool -classtype_has_nothrow_copy_or_assign_p (tree type, bool copy_p) +classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p) { - if ((copy_p && TYPE_HAS_INIT_REF (type)) - || (!copy_p && TYPE_HAS_ASSIGN_REF (type))) + tree fns; + + if (assign_p) { - bool const_p = false; - tree t; - - struct copy_data - { - tree name; - int quals; - } data; - - data.name = copy_p ? NULL_TREE : ansi_assopname (NOP_EXPR); - - data.quals = TYPE_QUAL_CONST; - t = locate_copy (type, &data); - if (t) - { - const_p = true; - if (!TREE_NOTHROW (t)) - return false; - } - - if (copy_p || !CP_TYPE_CONST_P (type)) - { - data.quals = TYPE_UNQUALIFIED; - t = locate_copy (type, &data); - if (t && !TREE_NOTHROW (t)) - return false; - - data.quals = TYPE_QUAL_VOLATILE; - t = locate_copy (type, &data); - if (t && !TREE_NOTHROW (t)) - return false; - } - - data.quals = (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); - t = locate_copy (type, &data); - if (t) - { - const_p = true; - if (!TREE_NOTHROW (t)) - return false; - } - - if (!copy_p && CP_TYPE_CONST_P (type) && !const_p) + int ix; + ix = lookup_fnfields_1 (type, ansi_assopname (NOP_EXPR)); + if (ix < 0) return false; + fns = VEC_index (tree, CLASSTYPE_METHOD_VEC (type), ix); + } + else if (TYPE_HAS_INIT_REF (type)) + { + /* If construction of the copy constructor was postponed, create + it now. */ + if (CLASSTYPE_LAZY_COPY_CTOR (type)) + lazily_declare_fn (sfk_copy_constructor, type); + fns = CLASSTYPE_CONSTRUCTORS (type); } else return false; + for (; fns; fns = OVL_NEXT (fns)) + if (!TREE_NOTHROW (OVL_CURRENT (fns))) + return false; + return true; } @@ -4080,9 +4054,11 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) switch (kind) { case CPTK_HAS_NOTHROW_ASSIGN: - return (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2) - || (CLASS_TYPE_P (type1) - && classtype_has_nothrow_copy_or_assign_p (type1, false))); + return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE + && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2) + || (CLASS_TYPE_P (type1) + && classtype_has_nothrow_assign_or_copy_p (type1, + true)))); case CPTK_HAS_TRIVIAL_ASSIGN: return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE @@ -4104,7 +4080,7 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_HAS_NOTHROW_COPY: return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2) || (CLASS_TYPE_P (type1) - && classtype_has_nothrow_copy_or_assign_p (type1, true))); + && classtype_has_nothrow_assign_or_copy_p (type1, false))); case CPTK_HAS_TRIVIAL_COPY: return (pod_type_p (type1) || type_code1 == REFERENCE_TYPE diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index ce63202ebb0..45a632493de 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -11246,13 +11246,12 @@ pair of types). @table @code @item __has_nothrow_assign (type) -If @code{__has_trivial_assign (type)} is true then the trait is true, else if -@code{type} is a cv class or union type with copy assignment operators that -are known not to throw an exception then the trait is true, else it is false. -If @code{type} is const qualified, any copy assignment operator must -be both known not to throw an exception, and const qualified, for the -trait to be true. Requires: @code{type} shall be a complete type, an -array type of unknown bound, or is a @code{void} type. +If @code{type} is const qualified or is a reference type then the trait is +false. Otherwise if @code{__has_trivial_assign (type)} is true then the trait +is true, else if @code{type} is a cv class or union type with copy assignment +operators that are known not to throw an exception then the trait is true, +else it is false. Requires: @code{type} shall be a complete type, an array +type of unknown bound, or is a @code{void} type. @item __has_nothrow_copy (type) If @code{__has_trivial_copy (type)} is true then the trait is true, else if diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9dc7a398a5d..c7f3dbb80e2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2007-04-25 Paolo Carlini + + * g++.dg/ext/has_nothrow_assign.C: Adjust per N2255. + 2007-04-25 Thiemo Seufer * gcc.target/mips/mips16e-extends.c (cksum8): Change return diff --git a/gcc/testsuite/g++.dg/ext/has_nothrow_assign.C b/gcc/testsuite/g++.dg/ext/has_nothrow_assign.C index f8790825351..5407b963e14 100644 --- a/gcc/testsuite/g++.dg/ext/has_nothrow_assign.C +++ b/gcc/testsuite/g++.dg/ext/has_nothrow_assign.C @@ -146,7 +146,7 @@ int main() assert (NTEST (I1)); assert (PTEST (J)); assert (NTEST (const K)); - assert (PTEST (const L)); + assert (NTEST (const L)); return 0; }