template<typename T>
class number {
T num;
public:
number(T num = 0): num(num) {}
friend auto add(auto a, auto b);
};
auto add(auto a, auto b) {
// the decltype(a) is needed to make clang happy
// see: https://stackoverflow.com/questions/62779242
return number<decltype(a)>{a}.num + number<decltype(b)>{b}.num;
}
int main() {
auto result = add(1.0, 2.0);
}gcc提供的编译错误(带有-std=c++20的10.1版):
In instantiation of 'auto add(auto:13, auto:14) [with auto:13 = double; auto:14 = double]':
error: 'double number<double>::num' is private within this context
return number<decltype(a)>{a}.num + number<decltype(b)>{b}.num;假设这是bug gcc是合理的吗?
发布于 2020-08-12 11:40:06
显然,这是GCC 10.1.0的一个错误,在正确工作到9.3之后。
https://stackoverflow.com/questions/62779488
复制相似问题