diff options
author | Jason Merrill <jason@redhat.com> | 2017-10-23 15:06:37 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2017-10-23 15:06:37 -0400 |
commit | 802561b2cc6cd4e4f59815f7de199026de62a650 (patch) | |
tree | d13759d2a3934d2bd328ea9ef4273a5ac58e9f73 /gcc | |
parent | 52c91d3aaf983110034f894a555e3ebb9c4fa3e6 (diff) | |
download | gcc-802561b2cc6cd4e4f59815f7de199026de62a650.zip gcc-802561b2cc6cd4e4f59815f7de199026de62a650.tar.gz gcc-802561b2cc6cd4e4f59815f7de199026de62a650.tar.bz2 |
PR c++/77369 - wrong noexcept handling in C++14 and below
* tree.c (strip_typedefs): Canonicalize TYPE_RAISES_EXCEPTIONS.
From-SVN: r254022
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/tree.c | 11 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/noexcept31.C | 12 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1z/noexcept-type13.C | 2 |
4 files changed, 25 insertions, 5 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ed89364..9514e9c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2017-10-23 Jason Merrill <jason@redhat.com> + + PR c++/77369 - wrong noexcept handling in C++14 and below + * tree.c (strip_typedefs): Canonicalize TYPE_RAISES_EXCEPTIONS. + 2017-10-20 Nathan Sidwell <nathan@acm.org> * class.c (layout_class_type): Cleanup as-base creation, determine diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 366f46f..48d4094 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1439,7 +1439,11 @@ strip_typedefs (tree t, bool *remove_attributes) is_variant = true; type = strip_typedefs (TREE_TYPE (t), remove_attributes); - changed = type != TREE_TYPE (t) || is_variant; + tree canon_spec = (flag_noexcept_type + ? canonical_eh_spec (TYPE_RAISES_EXCEPTIONS (t)) + : NULL_TREE); + changed = (type != TREE_TYPE (t) || is_variant + || TYPE_RAISES_EXCEPTIONS (t) != canon_spec); for (arg_node = TYPE_ARG_TYPES (t); arg_node; @@ -1498,9 +1502,8 @@ strip_typedefs (tree t, bool *remove_attributes) type_memfn_rqual (t)); } - if (TYPE_RAISES_EXCEPTIONS (t)) - result = build_exception_variant (result, - TYPE_RAISES_EXCEPTIONS (t)); + if (canon_spec) + result = build_exception_variant (result, canon_spec); if (TYPE_HAS_LATE_RETURN_TYPE (t)) TYPE_HAS_LATE_RETURN_TYPE (result) = 1; } diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept31.C b/gcc/testsuite/g++.dg/cpp0x/noexcept31.C new file mode 100644 index 0000000..c4c0e7d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept31.C @@ -0,0 +1,12 @@ +// PR c++/77369 +// { dg-do compile { target c++11 } } + +template<typename F> int caller(F f) noexcept(noexcept(f())) { f(); return 0; } + +void func1() noexcept { } + +void func2() { throw 1; } + +int instantiate_caller_with_func1 = caller(func1); + +static_assert( !noexcept(caller(func2)), "" ); diff --git a/gcc/testsuite/g++.dg/cpp1z/noexcept-type13.C b/gcc/testsuite/g++.dg/cpp1z/noexcept-type13.C index 8eb3be0..b51d7af 100644 --- a/gcc/testsuite/g++.dg/cpp1z/noexcept-type13.C +++ b/gcc/testsuite/g++.dg/cpp1z/noexcept-type13.C @@ -5,7 +5,7 @@ void foo () throw () {} // { dg-bogus "mangled name" } template <class T> -T bar (T x) { return x; } // { dg-warning "mangled name" "" { target c++14_down } } +T bar (T x) { return x; } void baz () { // { dg-bogus "mangled name" } return (bar (foo)) (); |