such code cause ICE or template instantiation depth exceeds maximum error,
if uncomment (1) and comment (2) all compiles successfully.

#include <cstdlib>
#include <cstdio>

template <typename T>
struct ConstDependOnType;

template <>
struct ConstDependOnType <int> {
  enum { val1 = 4 };
};

template <typename T>
struct Foo {
  //1
  //enum { val1 = 4 };
  //2
  enum { val1 = ConstDependOnType<T>::val1 };

  template <T a, int b> struct SubFoo;

  template <T a, int b = 0>
  struct SubFoo {
    enum { value = SubFoo<a + b, b + 1>::value };
  };

  template <T a>
  struct SubFoo<a, val1> {
    enum { value = a };
  };
};

int main()
{
  printf("%d\n", static_cast<int>(Foo<int>::SubFoo<5>::value));
}


-- 
           Summary: use in template constant from another template
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dushistov at mail dot ru


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

Reply via email to