From 7a1db261dec3c7da38f1576a03ec44167649c1af Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Sun, 22 May 2011 14:48:39 -0400 Subject: [PATCH] re PR c++/48647 ([C++0x] SFINAE does not handle incompatible pointer types well in conditional operator) PR c++/48647 * typeck.c (composite_pointer_type_r): Return error_mark_node on error in SFINAE context. From-SVN: r174031 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/typeck.c | 13 ++++++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/sfinae23.C | 28 +++++++++++++++++++++++++ gcc/testsuite/g++.dg/template/sfinae8.C | 4 ++-- 5 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/sfinae23.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d487e84ac5b..e6399d364e9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2011-05-22 Jason Merrill + + PR c++/48647 + * typeck.c (composite_pointer_type_r): Return error_mark_node + on error in SFINAE context. + 2011-05-20 Jason Merrill PR c++/48945 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 7791efcaa8f..dd1cc3b127c 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -516,7 +516,8 @@ composite_pointer_type_r (tree t1, tree t2, { if (complain & tf_error) composite_pointer_error (DK_PERMERROR, t1, t2, operation); - + else + return error_mark_node; result_type = void_type_node; } result_type = cp_build_qualified_type (result_type, @@ -527,9 +528,13 @@ composite_pointer_type_r (tree t1, tree t2, if (TYPE_PTR_TO_MEMBER_P (t1)) { if (!same_type_p (TYPE_PTRMEM_CLASS_TYPE (t1), - TYPE_PTRMEM_CLASS_TYPE (t2)) - && (complain & tf_error)) - composite_pointer_error (DK_PERMERROR, t1, t2, operation); + TYPE_PTRMEM_CLASS_TYPE (t2))) + { + if (complain & tf_error) + composite_pointer_error (DK_PERMERROR, t1, t2, operation); + else + return error_mark_node; + } result_type = build_ptrmem_type (TYPE_PTRMEM_CLASS_TYPE (t1), result_type); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 74831063f8e..f083968b1c6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-05-22 Jason Merrill + + * g++.dg/cpp0x/sfinae23.C: New. + * g++.dg/cpp0x/sfinae8.C: Correct. + 2011-05-22 Thomas Koenig * gfortran.dg/function_optimize_8.f90: New test case. diff --git a/gcc/testsuite/g++.dg/cpp0x/sfinae23.C b/gcc/testsuite/g++.dg/cpp0x/sfinae23.C new file mode 100644 index 00000000000..4e2ea88b171 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/sfinae23.C @@ -0,0 +1,28 @@ +// PR c++/48647 +// { dg-options -std=c++0x } + +template< class T > +T&& declval(); + +template< class T, class U > +decltype( true ? declval() : declval() ) test( int ); + +template< class T, class U > +void test( ... ); + + +template< class T, class U > +struct is_same { + static const bool value = false; +}; + +template< class T > +struct is_same { + static const bool value = true; +}; + +#define SA(X) static_assert ((X),#X) + +typedef decltype( test(0) ) void_expected; +SA ((is_same::value)); +SA ((!is_same::value)); diff --git a/gcc/testsuite/g++.dg/template/sfinae8.C b/gcc/testsuite/g++.dg/template/sfinae8.C index 2ad68dc5dbf..5ac09c6b3b8 100644 --- a/gcc/testsuite/g++.dg/template/sfinae8.C +++ b/gcc/testsuite/g++.dg/template/sfinae8.C @@ -120,7 +120,7 @@ STATIC_ASSERT((!is_equality_comparable::value)); STATIC_ASSERT((!is_equality_comparable::value)); STATIC_ASSERT((is_equality_comparable::value)); STATIC_ASSERT((!is_equality_comparable::value)); -STATIC_ASSERT((is_equality_comparable::value)); +STATIC_ASSERT((!is_equality_comparable::value)); STATIC_ASSERT((is_equality_comparable::value)); STATIC_ASSERT((!is_equality_comparable::value)); @@ -139,7 +139,7 @@ STATIC_ASSERT((!is_not_equal_comparable::value)); STATIC_ASSERT((!is_not_equal_comparable::value)); STATIC_ASSERT((is_not_equal_comparable::value)); STATIC_ASSERT((!is_not_equal_comparable::value)); -STATIC_ASSERT((is_not_equal_comparable::value)); +STATIC_ASSERT((!is_not_equal_comparable::value)); STATIC_ASSERT((is_not_equal_comparable::value)); STATIC_ASSERT((!is_not_equal_comparable::value)); -- 2.30.2