【发布时间】:2012-12-13 22:06:13
【问题描述】:
我刚刚在 GCC 中遇到了以下警告:
warning: implicit dereference will not access object of type ‘volatile util::Yield’ in statement [enabled by default]
编译这段代码时:
volatile util::Yield y1;
util::Yield y2;
y1 += y2; // <--- Warning triggered here.
不幸的是,我不太明白 GCC 试图告诉我什么......
Yield 类声明如下:
class Yield {
public:
Yield();
Yield &operator+=(Yield const &other);
Yield &operator+=(Yield const volatile &other);
Yield volatile &operator+=(Yield const &other) volatile;
Yield volatile &operator+=(Yield const volatile &other) volatile;
// Other operators snipped...
};
有什么想法吗?
谢谢!
【问题讨论】:
-
这个警告对于 c++11 来说应该是过时的,因为在 c++11 中函数调用的左值将不再被读取。
-
@JohannesSchaub-litb:已经有几年了,但我仍然在 C++14 中收到此警告(目前在 GCC 最新版本中对此感到沮丧)。我想知道是否有更深层次的需要,或者它只是一个遗物。最近的 clang 没有给出这样的警告,但似乎从来没有这样做过,查看 Godbolt 中的旧版本。
标签: c++ gcc gcc-warning