[Bug c++/44907] New: SFINAE vs ambiguous base (the real one ;)

paolo dot carlini at oracle dot com gcc-bugzilla@gcc.gnu.org
Sat Jul 10 20:16:00 GMT 2010


OK, this time is for real. I have almost ready a library-only is_convertible
which purely uses SFINAE and noticed that apparently we have a remaining issue
with ambiguous bases, not fixed by your recent patch. The testcase goes like
this, I already checked that ICC likes it:

// #include <type_traits> 

struct A { };

struct B
: A { };

struct C
: A { };

struct D
: B, C { };

template<bool, typename T = void> struct enable_if { typedef T type; };
template<typename T> struct enable_if<false, T> { };

template<typename From, typename To>
  class mini_is_convertible
  {
    typedef char one;
    typedef struct { char arr[2]; } two;

    template<typename To1>
      static void test_aux(To1);

    template<typename To1, typename From1>
      // static decltype(test_aux<To1>(std::declval<From1>()), one())
      static typename
      enable_if<(sizeof(test_aux<To1>(From1()), 1) > 0), one>::type
      test(int);

    template<typename, typename>
      static two test(...);

    public:
      static const bool value = sizeof(test<To, From>(0)) == 1;
  }; 

int main()
{
 mini_is_convertible<D*, A*>::value; // compiles with 4.6 (false)
 mini_is_convertible<D, A>::value;   // does not compile (ok with ICC (false)) 
}

I would suggest double-checking the C++0x version too, using decltype and, more
correctly, declval.


-- 
           Summary: SFINAE vs ambiguous base (the real one ;)
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: paolo dot carlini at oracle dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44907



More information about the Gcc-bugs mailing list