[cfe-dev] curious "apparent" gcc bug that clang seems to get right
Joshua Cranmer 🐧
Pidgeot18 at gmail.com
Wed Dec 4 21:58:04 PST 2013
On 12/4/2013 10:51 PM, reed kotler wrote:
> I'm not sure myself enough of how, if at all, volatile is inherited
> into a class from it's members.
> But the following code, boiled down from some complicated android code
> is essentially.
> This same problem happens for gcc x86 and mips.
> Anyone care to weigh in on a proper reading of the C or C++ standard
> for this?
C++11 makes this easier to follow. The case this boils down to is the
defaulted copy assignment operator for union like classes:
The implicitly-defined copy assignment operator for a union X copies the
object representation (3.9) of X.
As a result, the fact that the member y is volatile is completely
ignored in C++. C11 is much less clear on the subject, but as far as I
can make it, the assignment operator is considered to copy the union
object and not the volatile int subobject contained within, although you
could easily hide behind section 6.7.3's note that "what constitutes an
access to an object that has volatile-qualified type is
Thunderbird and DXR developer
Source code archæologist
More information about the cfe-dev