From d0bb79ac89f08dbc31be9d0427e9a16ea16fa37d Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 7 Apr 2011 17:48:00 -0400 Subject: [PATCH] re PR c++/48468 ([C++0x][SFINAE] noexcept operator does not handle function templates well) PR c++/48468 * except.c (build_noexcept_spec): Propagate error_mark_node. (finish_noexcept_expr): Likewise. From-SVN: r172148 --- gcc/cp/ChangeLog | 4 ++ gcc/cp/except.c | 5 +++ gcc/testsuite/ChangeLog | 3 ++ gcc/testsuite/g++.dg/cpp0x/noexcept02.C | 4 +- gcc/testsuite/g++.dg/cpp0x/sfinae11.C | 56 +++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/sfinae11.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 04b9c402723..d20cf5165a3 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2011-04-07 Jason Merrill + PR c++/48468 + * except.c (build_noexcept_spec): Propagate error_mark_node. + (finish_noexcept_expr): Likewise. + PR c++/48452 * typeck.c (build_x_compound_expr_from_list): Return error_mark_node in SFINAE context. diff --git a/gcc/cp/except.c b/gcc/cp/except.c index a814d678658..874f1115044 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -1125,6 +1125,9 @@ finish_noexcept_expr (tree expr, tsubst_flags_t complain) { tree fn; + if (expr == error_mark_node) + return error_mark_node; + if (processing_template_decl) return build_min (NOEXCEPT_EXPR, boolean_type_node, expr); @@ -1212,6 +1215,8 @@ build_noexcept_spec (tree expr, int complain) return noexcept_true_spec; else if (expr == boolean_false_node) return noexcept_false_spec; + else if (expr == error_mark_node) + return error_mark_node; else { gcc_assert (processing_template_decl || expr == error_mark_node); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 38f097208e5..dc446df8a0b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2011-04-07 Jason Merrill + * g++.dg/cpp0x/sfinae11.C: New. + * g++.dg/cpp0x/noexcept02.C: Fix. + * g++.dg/cpp0x/sfinae10.C: New. * g++.dg/cpp0x/sfinae9.C: New. diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept02.C b/gcc/testsuite/g++.dg/cpp0x/noexcept02.C index be6fa00dd09..60015e75668 100644 --- a/gcc/testsuite/g++.dg/cpp0x/noexcept02.C +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept02.C @@ -46,7 +46,9 @@ SA(!noexcept(f3(A()))); template void f (T1, T2) noexcept(noexcept(T1(), T2())); -SA(noexcept(f3(1,1))); +struct B { }; + +SA(noexcept(f3(1,B()))); SA(!noexcept(f3(1,A()))); SA(!noexcept(f3(A(),1))); SA(!noexcept(f3(A(),A()))); diff --git a/gcc/testsuite/g++.dg/cpp0x/sfinae11.C b/gcc/testsuite/g++.dg/cpp0x/sfinae11.C new file mode 100644 index 00000000000..a3ffc34f9a3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/sfinae11.C @@ -0,0 +1,56 @@ +// PR c++/48468 +// { dg-options -std=c++0x } +// { dg-prune-output "note" } + +template +T&& declval() noexcept; + +template< class T > +inline void f1( T& x ) noexcept( noexcept( declval().foo() ) ) +{ + x.foo(); +} + +template< class T, + bool Noexcept = noexcept( declval().foo() ) +> +inline void f2( T& x ) noexcept( Noexcept ) +{ + x.foo(); +} + +// a common and trivial mistake +template< class T > +inline void f3( T& x ) noexcept( declval().foo() ) +{ + x.foo(); +} + +struct X +{ + void foo(); +}; + +struct Y +{ + void foo() noexcept; +}; + +struct Z {}; + +int main() +{ + X x; Y y; Z z; + + static_assert( !noexcept( f1(x) ), "OK." ); + static_assert( !noexcept( f2(x) ), "OK." ); + // static_assert( !noexcept( f3(x) ), "shall be ill-formed(OK)." ); + + static_assert( noexcept( f1(y) ), "OK." ); + static_assert( noexcept( f2(y) ), "OK." ); + // static_assert( noexcept( f3(y) ), "shall be ill-formed(OK)." ); + + static_assert( noexcept( f1(z) ), "shall be ill-formed." ); // { dg-error "no match" } + static_assert( noexcept( f2(z) ), "shall be ill-formed." ); // { dg-error "no match" } + static_assert( !noexcept( f3(z) ), "shall be ill-formed." ); // { dg-error "no match" } +} -- 2.30.2