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

            Bug ID: 57783
           Summary: Silly instantiation of class template when using
                    dependent type
           Product: gcc
           Version: 4.4.7
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ibugs at qult dot net

The following code fails to compile on GCC 4.4.7, while it succeeds on 3.3.6,
4.5.3, 4.6.3, 4.6.4 and 4.7.3.

template <class T1, class T2>
struct Two {
  T1    a;
  T2    b;
  Two(const T1& a_, const T2& b_) : a(a_), b(b_) {}

  template <class U1, class U2>
  Two(const Two<U1, U2>& t) : a(t.a), b(t.b) {}
};

template <class T1, class T2>
Two<T1, T2>    make_two(T1 a, T2 b) {
  return Two<T1, T2>(a, b);
}

struct Empty {};

template <class Base>
struct Foo : Base {
  typedef bool    type;

  Two<bool, type*>    f();
};

template <class Base>
Two<bool, typename Foo<Base>::type*>
Foo<Base>::f() {
  return make_two(false, (type*) 0);
}

int main()
{
  Foo<Empty>().f();
  return 0;
}

Apparently the instantiation mechanism somehow has trouble dealing with
Foo<Base>::type and doesn't identify this with the exact type (bool).

The very curious fact is that the error message starts with:

  In instantiation of 'Foo<bool>':

which makes me wonder, how comes GCC wants to instantiate a class template with
some completely random parameter.

This seems to be fixed in later releases, but I haven't been able to pinpoint
the actual report and fix.  So I report that specific case just to be sure that
problem won't resurrect in the future.

Reply via email to