From 247078ec4ddf45f168329c23187f480355b43f90 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Sat, 5 Jun 2010 00:52:07 -0400 Subject: typeck2.c (merge_exception_specifiers): Adjust merging of throw() and noexcept(true). * typeck2.c (merge_exception_specifiers): Adjust merging of throw() and noexcept(true). From-SVN: r160308 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/typeck2.c | 11 ++++------- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/cpp0x/noexcept06.C | 29 +++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/cpp0x/noexcept07.C | 25 +++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept06.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept07.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a67de73..b051079 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2010-06-04 Jason Merrill + * typeck2.c (merge_exception_specifiers): Adjust merging of + throw() and noexcept(true). + * pt.c (value_dependent_expression_p) [NOEXCEPT_EXPR]: Avoid using an uninitialized variable. diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 93ea70d..e7b97c4 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -1721,17 +1721,14 @@ merge_exception_specifiers (tree list, tree add) { if (!list || !add) return NULL_TREE; - /* A noexcept(true) spec takes precedence over a throw() spec. + /* For merging noexcept(true) and throw(), take the more recent one (LIST). A throw(type-list) spec takes precedence over a noexcept(false) spec. Any other noexcept-spec should only be merged with an equivalent one. - So the !TREE_VALUE code is correct for the latter two cases. */ - else if (list == noexcept_true_spec - || add == noexcept_true_spec) - return noexcept_true_spec; - else if (!TREE_VALUE (list)) - return add; + So the !TREE_VALUE code below is correct for all cases. */ else if (!TREE_VALUE (add)) return list; + else if (!TREE_VALUE (list)) + return add; else { tree orig_list = list; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7fe8c50..0998820 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2010-06-04 Jason Merrill + * g++.dg/cpp0x/noexcept06.C: New. + * g++.dg/cpp0x/noexcept07.C: New. + * g++.dg/cpp0x/noexcept01.C: New. * g++.dg/cpp0x/noexcept02.C: New. * g++.dg/cpp0x/noexcept03.C: New. diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept06.C b/gcc/testsuite/g++.dg/cpp0x/noexcept06.C new file mode 100644 index 0000000..b0135ac --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept06.C @@ -0,0 +1,29 @@ +// Test that checking of a nothrow specification uses the one on the +// definition. +// { dg-options "-std=c++0x" } +// { dg-do run } + +#include +#include + +void my_unexpected () +{ + std::abort (); +} +void my_terminate () +{ + std::exit (0); +} + +void f() throw(); +void f() noexcept +{ + throw 1; +} + +int main() +{ + std::set_terminate (my_terminate); + f(); + return 1; +} diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept07.C b/gcc/testsuite/g++.dg/cpp0x/noexcept07.C new file mode 100644 index 0000000..0a5773f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept07.C @@ -0,0 +1,25 @@ +// Test that checking of a nothrow specification uses the one on the +// definition. +// { dg-options "-std=c++0x" } +// { dg-do run } + +#include +#include + +void my_unexpected () +{ + std::exit (0); +} + +void f() noexcept; +void f() throw() +{ + throw 1; +} + +int main() +{ + std::set_unexpected (my_unexpected); + f(); + return 1; +} -- cgit v1.1