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

            Bug ID: 59383
           Summary: typedef propagation with template base class using the
                    same name is wrong
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gmarkhor at gmail dot com

I am using g++ 4.8.1. Consider the following code (compiled as g++ -std=c++11
-c test.cc):

#include <type_traits>

template <typename F, typename S>
struct TypePair {
  typedef F First;
  typedef S Second;
};

template <int I>
class Base {
 public:
  typedef TypePair<Base, Base> Family;
  typedef Base ParentType;
};

template <int I>
class Derived : public Base<I> {
 public:
  typedef TypePair<Derived, typename Derived::Family::First> Family;
  typedef typename Family::Second ParentType;
};

static_assert(std::is_same<Base<1>, Derived<1>::ParentType>::value, "Error");




The static assertion is failed. Clang ver. 3.2 and 3.3 and 3.4 compiles this
code well.

If you remove the template from Base:




#include <type_traits>

template <typename F, typename S>
struct TypePair {
  typedef F First;
  typedef S Second;
};

class Base {
 public:
  typedef TypePair<Base, Base> Family;
  typedef Base ParentType;
};

template <int I>
class Derived : public Base {
 public:
  typedef TypePair<Derived, typename Derived::Family::First> Family;
  typedef typename Family::Second ParentType;
};

static_assert(std::is_same<Base, Derived<1>::ParentType>::value, "Error");




then everything becomes OK. The other way to make it work is to remove template
from Derived and inherit from an explicit Base<1>:





#include <type_traits>

template <typename F, typename S>
struct TypePair {
  typedef F First;
  typedef S Second;
};

template <int I>
class Base {
 public:
  typedef TypePair<Base, Base> Family;
  typedef Base ParentType;
};

class Derived : public Base<1> {
 public:
  typedef TypePair<Derived, typename Derived::Family::First> Family;
  typedef typename Family::Second ParentType;
};

static_assert(std::is_same<Base<1>, Derived::ParentType>::value, "Error");



I am not sure what standard says about this, but it seems a bug.

Reply via email to