From: Paolo Carlini Date: Mon, 21 Jul 2008 09:08:41 +0000 (+0000) Subject: re PR c++/36870 (__has_nothrow_constructor violates the ODR) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e24313f349328c3fc973375cab9c3818388308ba;p=gcc.git re PR c++/36870 (__has_nothrow_constructor violates the ODR) /cp 2008-07-21 Paolo Carlini PR c++/36870 * semantics.c (classtype_has_nothrow_assign_or_copy_p): Use TYPE_NOTHROW_P, not TREE_NOTHROW. (trait_expr_value): Likewise. /testsuite 2008-07-21 Paolo Carlini PR c++/36870 * g++.dg/ext/has_nothrow_assign_odr.C: New. * g++.dg/ext/has_nothrow_copy_odr.C: Likewise. * g++.dg/ext/has_nothrow_constructor_odr.C: Likewise. * g++.dg/ext/has_nothrow_assign.C: Adjust. * g++.dg/ext/has_nothrow_copy.C: Likewise. * g++.dg/ext/has_nothrow_constructor.C: Likewise. From-SVN: r138024 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2112b8fd8e6..913f3284ba9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2008-07-21 Paolo Carlini + + PR c++/36870 + * semantics.c (classtype_has_nothrow_assign_or_copy_p): Use + TYPE_NOTHROW_P, not TREE_NOTHROW. + (trait_expr_value): Likewise. + 2008-07-18 Dodji Seketeli PR c++/36407 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index d2f56ea810a..3b91ddb0f90 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -4677,7 +4677,7 @@ classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p) return false; for (; fns; fns = OVL_NEXT (fns)) - if (!TREE_NOTHROW (OVL_CURRENT (fns))) + if (!TYPE_NOTHROW_P (TREE_TYPE (OVL_CURRENT (fns)))) return false; return true; @@ -4712,7 +4712,8 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) type1 = strip_array_types (type1); return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2) || (CLASS_TYPE_P (type1) - && (t = locate_ctor (type1, NULL)) && TREE_NOTHROW (t))); + && (t = locate_ctor (type1, NULL)) + && TYPE_NOTHROW_P (TREE_TYPE (t)))); case CPTK_HAS_TRIVIAL_CONSTRUCTOR: type1 = strip_array_types (type1); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bd32d6c68bc..13f14681780 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,13 @@ +2008-07-21 Paolo Carlini + + PR c++/36870 + * g++.dg/ext/has_nothrow_assign_odr.C: New. + * g++.dg/ext/has_nothrow_copy_odr.C: Likewise. + * g++.dg/ext/has_nothrow_constructor_odr.C: Likewise. + * g++.dg/ext/has_nothrow_assign.C: Adjust. + * g++.dg/ext/has_nothrow_copy.C: Likewise. + * g++.dg/ext/has_nothrow_constructor.C: Likewise. + 2008-07-17 Andreas Krebbel PR target/36822 diff --git a/gcc/testsuite/g++.dg/ext/has_nothrow_assign.C b/gcc/testsuite/g++.dg/ext/has_nothrow_assign.C index 525cac7aa48..73a904eac25 100644 --- a/gcc/testsuite/g++.dg/ext/has_nothrow_assign.C +++ b/gcc/testsuite/g++.dg/ext/has_nothrow_assign.C @@ -136,19 +136,13 @@ int main() assert (PTEST (C)); assert (NTEST (C[])); assert (PTEST (D)); -#ifndef __PIC__ - assert (PTEST (E)); -#endif + assert (NTEST (E)); assert (NTEST (E1)); assert (PTEST (F)); assert (PTEST (G)); -#ifndef __PIC__ - assert (PTEST (H)); -#endif + assert (NTEST (H)); assert (NTEST (H1)); -#ifndef __PIC__ - assert (PTEST (I)); -#endif + assert (NTEST (I)); assert (NTEST (I1)); assert (PTEST (J)); assert (NTEST (const K)); diff --git a/gcc/testsuite/g++.dg/ext/has_nothrow_assign_odr.C b/gcc/testsuite/g++.dg/ext/has_nothrow_assign_odr.C new file mode 100644 index 00000000000..c38d76d44a6 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/has_nothrow_assign_odr.C @@ -0,0 +1,16 @@ +// PR c++/36870 +// { dg-do "run" } +#include + +struct S { const S& operator= (const S&); }; + +bool f (); + +int main () +{ + assert (__has_nothrow_assign (S) == f ()); +} + +const S& S::operator= (const S&) { } + +bool f () { return __has_nothrow_assign (S); } diff --git a/gcc/testsuite/g++.dg/ext/has_nothrow_constructor.C b/gcc/testsuite/g++.dg/ext/has_nothrow_constructor.C index 7e747bcd11e..60e9be8d0be 100644 --- a/gcc/testsuite/g++.dg/ext/has_nothrow_constructor.C +++ b/gcc/testsuite/g++.dg/ext/has_nothrow_constructor.C @@ -97,9 +97,7 @@ int main() assert (PTEST (C)); assert (PTEST (C[])); assert (PTEST (D)); -#ifndef __PIC__ - assert (PTEST (E)); -#endif + assert (NTEST (E)); assert (NTEST (E1)); assert (NTEST (F)); assert (NTEST (G)); diff --git a/gcc/testsuite/g++.dg/ext/has_nothrow_constructor_odr.C b/gcc/testsuite/g++.dg/ext/has_nothrow_constructor_odr.C new file mode 100644 index 00000000000..775e74a2631 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/has_nothrow_constructor_odr.C @@ -0,0 +1,16 @@ +// PR c++/36870 +// { dg-do "run" } +#include + +struct S { S (); }; + +bool f (); + +int main () +{ + assert (__has_nothrow_constructor (S) == f ()); +} + +S::S () { } + +bool f () { return __has_nothrow_constructor (S); } diff --git a/gcc/testsuite/g++.dg/ext/has_nothrow_copy.C b/gcc/testsuite/g++.dg/ext/has_nothrow_copy.C index 6843d51b4c4..e8507cf582c 100644 --- a/gcc/testsuite/g++.dg/ext/has_nothrow_copy.C +++ b/gcc/testsuite/g++.dg/ext/has_nothrow_copy.C @@ -126,19 +126,13 @@ int main() assert (PTEST (C)); assert (NTEST (C[])); assert (PTEST (D)); -#ifndef __PIC__ - assert (PTEST (E)); -#endif + assert (NTEST (E)); assert (NTEST (E1)); assert (PTEST (F)); assert (PTEST (G)); -#ifndef __PIC__ - assert (PTEST (H)); -#endif + assert (NTEST (H)); assert (NTEST (H1)); -#ifndef __PIC__ - assert (PTEST (I)); -#endif + assert (NTEST (I)); assert (NTEST (I1)); assert (PTEST (J)); diff --git a/gcc/testsuite/g++.dg/ext/has_nothrow_copy_odr.C b/gcc/testsuite/g++.dg/ext/has_nothrow_copy_odr.C new file mode 100644 index 00000000000..499a11e25be --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/has_nothrow_copy_odr.C @@ -0,0 +1,16 @@ +// PR c++/36870 +// { dg-do "run" } +#include + +struct S { S (const S&); }; + +bool f (); + +int main () +{ + assert (__has_nothrow_copy (S) == f ()); +} + +S::S (const S&) { } + +bool f () { return __has_nothrow_copy (S); }