From 279086c39066177adac8f9589683429e01c325a3 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 21 Jul 2008 16:18:38 +0000 Subject: [PATCH] re PR c++/36871 (__has_nothrow_copy(T) false for T with a template ctor) /cp 2008-07-21 Paolo Carlini PR c++/36871 PR c++/36872 * semantics.c (classtype_has_nothrow_assign_or_copy_p): Only check copy constructors and copy assignment operators proper. /testsuite 2008-07-21 Paolo Carlini PR c++/36871 PR c++/36872 * g++.dg/ext/has_nothrow_copy.C: Rename to... * g++.dg/ext/has_nothrow_copy-1.C: ... this. * g++.dg/ext/has_nothrow_copy-2.C: New. * g++.dg/ext/has_nothrow_copy-3.C: Likewise. * g++.dg/ext/has_nothrow_copy-4.C: Likewise. * g++.dg/ext/has_nothrow_copy-5.C: Likewise. * g++.dg/ext/has_nothrow_copy-6.C: Likewise. * g++.dg/ext/has_nothrow_copy-7.C: Likewise. From-SVN: r138034 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/semantics.c | 16 ++++++++++++++-- gcc/testsuite/ChangeLog | 13 +++++++++++++ .../{has_nothrow_copy.C => has_nothrow_copy-1.C} | 0 gcc/testsuite/g++.dg/ext/has_nothrow_copy-2.C | 12 ++++++++++++ gcc/testsuite/g++.dg/ext/has_nothrow_copy-3.C | 13 +++++++++++++ gcc/testsuite/g++.dg/ext/has_nothrow_copy-4.C | 13 +++++++++++++ gcc/testsuite/g++.dg/ext/has_nothrow_copy-5.C | 13 +++++++++++++ gcc/testsuite/g++.dg/ext/has_nothrow_copy-6.C | 12 ++++++++++++ gcc/testsuite/g++.dg/ext/has_nothrow_copy-7.C | 13 +++++++++++++ 10 files changed, 110 insertions(+), 2 deletions(-) rename gcc/testsuite/g++.dg/ext/{has_nothrow_copy.C => has_nothrow_copy-1.C} (100%) create mode 100644 gcc/testsuite/g++.dg/ext/has_nothrow_copy-2.C create mode 100644 gcc/testsuite/g++.dg/ext/has_nothrow_copy-3.C create mode 100644 gcc/testsuite/g++.dg/ext/has_nothrow_copy-4.C create mode 100644 gcc/testsuite/g++.dg/ext/has_nothrow_copy-5.C create mode 100644 gcc/testsuite/g++.dg/ext/has_nothrow_copy-6.C create mode 100644 gcc/testsuite/g++.dg/ext/has_nothrow_copy-7.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4e3bb4cd898..4f9e10c709d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2008-07-21 Paolo Carlini + + PR c++/36871 + PR c++/36872 + * semantics.c (classtype_has_nothrow_assign_or_copy_p): Only check + copy constructors and copy assignment operators proper. + 2008-07-21 Rafael Avila de Espindola * parser.c (cp_token): Remove in_system_header. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 3b91ddb0f90..ffa6493ced4 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -4677,8 +4677,20 @@ classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p) return false; for (; fns; fns = OVL_NEXT (fns)) - if (!TYPE_NOTHROW_P (TREE_TYPE (OVL_CURRENT (fns)))) - return false; + { + tree fn = OVL_CURRENT (fns); + + if (assign_p) + { + if (copy_fn_p (fn) == 0) + continue; + } + else if (copy_fn_p (fn) <= 0) + continue; + + if (!TYPE_NOTHROW_P (TREE_TYPE (fn))) + return false; + } return true; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d02787b284a..3f15e389096 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,16 @@ +2008-07-21 Paolo Carlini + + PR c++/36871 + PR c++/36872 + * g++.dg/ext/has_nothrow_copy.C: Rename to... + * g++.dg/ext/has_nothrow_copy-1.C: ... this. + * g++.dg/ext/has_nothrow_copy-2.C: New. + * g++.dg/ext/has_nothrow_copy-3.C: Likewise. + * g++.dg/ext/has_nothrow_copy-4.C: Likewise. + * g++.dg/ext/has_nothrow_copy-5.C: Likewise. + * g++.dg/ext/has_nothrow_copy-6.C: Likewise. + * g++.dg/ext/has_nothrow_copy-7.C: Likewise. + 2008-07-21 Thomas Koenig PR libfortran/36773 diff --git a/gcc/testsuite/g++.dg/ext/has_nothrow_copy.C b/gcc/testsuite/g++.dg/ext/has_nothrow_copy-1.C similarity index 100% rename from gcc/testsuite/g++.dg/ext/has_nothrow_copy.C rename to gcc/testsuite/g++.dg/ext/has_nothrow_copy-1.C diff --git a/gcc/testsuite/g++.dg/ext/has_nothrow_copy-2.C b/gcc/testsuite/g++.dg/ext/has_nothrow_copy-2.C new file mode 100644 index 00000000000..276b11d574c --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/has_nothrow_copy-2.C @@ -0,0 +1,12 @@ +// PR c++/36871 +// { dg-do "run" } +#include + +struct A { template A (T) throw (int); }; +struct B { B (B&) throw (); template B (T) throw (int); }; + +int main () +{ + assert (__has_nothrow_copy (A)); + assert (__has_nothrow_copy (B)); +} diff --git a/gcc/testsuite/g++.dg/ext/has_nothrow_copy-3.C b/gcc/testsuite/g++.dg/ext/has_nothrow_copy-3.C new file mode 100644 index 00000000000..2fbcf8c8096 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/has_nothrow_copy-3.C @@ -0,0 +1,13 @@ +// PR c++/36871 +// { dg-do "run" } +#include + +struct F { + F (const F&) throw () { } + template F (T) throw () { } +}; + +int main () +{ + assert (__has_nothrow_copy (F)); +} diff --git a/gcc/testsuite/g++.dg/ext/has_nothrow_copy-4.C b/gcc/testsuite/g++.dg/ext/has_nothrow_copy-4.C new file mode 100644 index 00000000000..4bd7475ea7c --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/has_nothrow_copy-4.C @@ -0,0 +1,13 @@ +// PR c++/36872 +// { dg-do "run" } +#include + +struct S { + S (const S&) throw (); + S (...) throw (int); +}; + +int main () +{ + assert (__has_nothrow_copy (S)); +} diff --git a/gcc/testsuite/g++.dg/ext/has_nothrow_copy-5.C b/gcc/testsuite/g++.dg/ext/has_nothrow_copy-5.C new file mode 100644 index 00000000000..051675c4d00 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/has_nothrow_copy-5.C @@ -0,0 +1,13 @@ +// PR c++/36872 +// { dg-do "run" } +#include + +struct S { + S (const S&) throw (); + S (int) throw (int); +}; + +int main () +{ + assert (__has_nothrow_copy (S)); +} diff --git a/gcc/testsuite/g++.dg/ext/has_nothrow_copy-6.C b/gcc/testsuite/g++.dg/ext/has_nothrow_copy-6.C new file mode 100644 index 00000000000..4330edd2941 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/has_nothrow_copy-6.C @@ -0,0 +1,12 @@ +// { dg-do "run" } +#include + +struct S { + S (S&) throw (); + S (const S&, int) throw (int); +}; + +int main () +{ + assert (__has_nothrow_copy (S)); +} diff --git a/gcc/testsuite/g++.dg/ext/has_nothrow_copy-7.C b/gcc/testsuite/g++.dg/ext/has_nothrow_copy-7.C new file mode 100644 index 00000000000..a85224c3abc --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/has_nothrow_copy-7.C @@ -0,0 +1,13 @@ +// { dg-do "run" } +// { dg-options "-std=c++0x" } +#include + +struct S { + S (const S&) throw (); + S (S&&) throw (int); +}; + +int main () +{ + assert (__has_nothrow_copy (S)); +} -- 2.30.2