【发布时间】:2016-04-07 08:15:01
【问题描述】:
此代码使用 clang 3.7.1 编译(没有诊断)但使用 GCC 5.3.0失败> (live example):
#include <iostream>
template<typename T>
struct A {
void foo()
{
static_cast<T*>(this)->implementation();
}
};
struct Crtp : A<Crtp> {
template<typename T>
friend struct A;
private:
void implementation() { std::cout << "implementation()\n"; }
};
int main()
{
Crtp c;
c.foo();
}
GCC的错误信息如下:
main.cpp:13:16: 错误:实例化后“A”的特化 朋友结构A;
哪一个是对的,为什么?是不是 GCC/clang 的 bug?
【问题讨论】: