【问题标题】:g++ 4.7.2 treatment of using for type aliasing seems to be brokeng++ 4.7.2 对使用类型别名的处理似乎被破坏了
【发布时间】:2013-08-13 15:48:01
【问题描述】:

在以下代码中,g++ 4.7.2 似乎被基于 using 的类型别名混淆了。

代码:

#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>();
}

编译代码:

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

意外的编译时错误:

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>'

有问题的行有什么问题?代码是否违反了 C++11 标准或者这是一个 g++ 4.7.2 错误? Live code in g++-4.7

【问题讨论】:

  • 用clang++编译很好,然后似乎是gcc问题...
  • 据我所知这是一个 g++ 错误。
  • 对于它的价值,4.8.1 编译它没有错误。
  • 很高兴知道,所以至少这个 4.7.2 的 bug 已经在 4.8.1 中修复了...
  • 这看起来像problem I had a while ago

标签: c++ c++11 g++ g++-4.7


【解决方案1】:

【讨论】:

  • 你试过 4.7.4 吗?也许错误修复被向后移植了。
  • 这是一项新功能,因此可能没有向后移植,但如果您尝试编辑答案,请随意。
猜你喜欢
  • 2020-02-22
  • 2023-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多