The following code refuses to compile :
----------------------------
struct C;

template < typename T >
struct B;

template < typename T >
struct A;

void f(const C &c);    // this one is fine
void f(const B<C> &a); // this one is fine
void f(const A<C> &a); // this one triggers the bug
void f(double) {}

template < typename T >
struct A
{
  B<T> b;
};


int main()
{
  f(1.0); // => instantiates A<C> => instantiates B<C> => fails.
}
-------------------------------

The error message is :
instance.C: In instantiation of 'A<C>':
instance.C:23:   instantiated from here
instance.C:17: error: 'A<T>::b' has incomplete type
instance.C:4: error: declaration of 'struct B<C>'

I am not 100% sure it is a SFINAE bug, but it looks like one to me.

Note that if you comment the declaration of f(A<C>), then it works.
Similarly if you comment the definition of A.

So the problem here is probably that if the definition of A is
available, then the compiler instantiates it, which triggers the
instantiation of B<T>, which fails, but the compiler does not
recover from this instantiation as it should (following SFINAE).

There is the same problem with g++ 3.3, 3.4 and 4.0.1.

-- 
           Summary: SFINAE bug
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sylvain dot pion at sophia dot inria dot fr
                CC: gcc-bugs at gcc dot gnu dot org,sylvain dot pion at
                    sophia dot inria dot fr
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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

Reply via email to