g++ 4.7.2 treatment of using for type aliasing seems to be broken

269 views Asked by At

In the following code, it would appear that g++ 4.7.2 gets confused by a using based type alias.

The code:

#include <map>

enum class Direction
{
  UP=-1,
  DOWN=1
};

template <Direction dir>
struct Comparator
{
  bool operator()(int lhs, int rhs) const
  {
    return lhs<rhs; // Comparison should be based on dir
                    // but let's not even use dir for now
  }
};

template <Direction dir>
using IntToIntMap=std::map<int, int, Comparator<dir>>;

template <Direction dir>
void TestFunc()
{
  using TheMap=IntToIntMap<dir>; // TheMap should be a synonym for
                                 // IntToIntMap<dir>

  typename IntToIntMap<dir>::value_type value1; // This compiles
  typename TheMap::value_type value2;           // This does not (???)
}

int main()
{
  TestFunc<Direction::UP>();
}

Compile the code with:

g++ -std=c++11 -Wall --pedantic -o test test.cpp

Unexpected compile time errors:

test.cpp: In instantiation of 'void TestFunc() [with Direction dir = 
                                                (Direction)-1]
test.cpp:34:29:   required from here
test.cpp:29:33: error: no type named 'value_type' in 'using TheMap = 
                                      IntToIntMap<dir>'

What is wrong with the line in question? Is the code in violation of the the C++11 standard or is this a g++ 4.7.2 bug? Live code in g++-4.7

1

There are 1 answers