小编iv_*_*iv_的帖子

GCC bug还是UB?这段代码应该编译吗?

下面的代码用clang编译好,但不用GCC编译(试过4.1.2,4.5.4和4.7.2):

template <typename T>
struct A
{
    struct B { };
};

template <typename T>
bool operator==(typename A<T>::B const& b, T const&  t);

enum { BAR };

template <typename T>
bool test()
{
    return 0 == BAR;
}
Run Code Online (Sandbox Code Playgroud)

GCC 4.7.2的错误消息是:

a.cpp: In instantiation of ‘struct A<<anonymous enum> >’:
a.cpp:12:6:   required by substitution of ‘template<class T> bool operator==(const typename A<T>::B&, const T&) [with T = <anonymous enum>]’
a.cpp:19:17:   required from here
a.cpp:6:12: error: ‘<anonymous enum>’ is/uses anonymous type
a.cpp:6:12: …
Run Code Online (Sandbox Code Playgroud)

c++ gcc gcc4.7

16
推荐指数
1
解决办法
641
查看次数

标签 统计

c++ ×1

gcc ×1

gcc4.7 ×1