Bug 48647

Summary: [C++0x] SFINAE does not handle incompatible pointer types well in conditional operator
Product: gcc Reporter: Takaya Saito <gintensubaru>
Component: c++Assignee: Jason Merrill <jason>
Status: RESOLVED FIXED    
Severity: normal CC: jason
Priority: P3    
Version: 4.7.0   
Target Milestone: 4.6.1   
See Also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48646
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2011-05-22 18:57:58

Description Takaya Saito 2011-04-17 07:48:51 UTC
template< class T >
T&& declval();

template< class T, class U >
decltype( true ? declval<T>() : declval<U>() ) 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<T, T> {
  static const bool value = true;
};

int main()
{
  typedef decltype( test<int*, double*>(0) ) void_expected;
  static_assert( is_same<void_expected, void>::value,  "This should be true, and" );
  static_assert( is_same<void_expected, void*>::value, "this should be false." );
}

-------------------


In this code, type of expression 'test<int*, double*>(0)' should be void,
but gcc (-std=c++0x) says it's void*, on all of following versions:

4.5.1
4.6.0
4.6.1-20110415
4.7.0-20110416
Comment 1 Paolo Carlini 2011-04-17 21:49:18 UTC
Likewise...
Comment 2 Jason Merrill 2011-05-22 18:48:42 UTC
Author: jason
Date: Sun May 22 18:48:39 2011
New Revision: 174031

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174031
Log:
	PR c++/48647
	* typeck.c (composite_pointer_type_r): Return error_mark_node
	on error in SFINAE context.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/sfinae23.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/template/sfinae8.C
Comment 3 Jason Merrill 2011-05-22 18:59:30 UTC
*** Bug 48646 has been marked as a duplicate of this bug. ***
Comment 4 Jason Merrill 2011-05-22 20:32:03 UTC
Author: jason
Date: Sun May 22 20:31:59 2011
New Revision: 174044

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=174044
Log:
	PR c++/48647
	* typeck.c (composite_pointer_type_r): Return error_mark_node
	on error in SFINAE context.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/sfinae23.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/typeck.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/template/sfinae8.C
Comment 5 Jason Merrill 2011-05-25 01:19:50 UTC
Fixed for 4.6.1.