GCC implicit dereference warning

I just met the following warning in GCC:

warning: implicit dereference will not access object of type 'volatile util::Yield' in statement [enabled by default] 

when compiling this code:

 volatile util::Yield y1; util::Yield y2; y1 += y2; // <--- Warning triggered here. 

and unfortunately, I don’t quite understand what the GCC is trying to tell me ...

The class output is declared as follows:

 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... }; 

Any ideas?

Thanks!

+7
source share
1 answer

From the GCC Guide, Section 6.1 - When is a modified object available?

When using the volatile reference, g ++ does not treat equivalent expressions as volatile references, but instead issues a warning that there is no volatile access. The rationale for this is that otherwise it becomes difficult to determine where volatile access occurs, and it is impossible to ignore the return value from functions that return volatile references. Again, if you want to force read, enter the rvalue link.

The warning stems from the fact that the + = operator returns a reference to a mutable object and that the expression 'y1 + = y2' ignores this return value. The compiler tells you that the link will not be dereferenced (i.e., the volatile value will not be read).

+5
source

All Articles