Whilst writing this answer I realised that I'm not as confident about my conclusions as I usually would ensure before hitting Post Your Answer.
I can find a couple of reasonably convincing citations for the argument that the trivial-copyability of volatile
data members is either implementation-defined or flat-out disallowed:
But I haven't been able to back this up in the standard1 itself. Particularly "worrying" is that there's no sign of the proposed wording change from that n3159 issues list in the actual standard's final wording.
So, what gives? Are volatile
data members trivially copyable, or not?
1 C++11
I'm seeing the following definition for "trivially copyable" (C++11 §3.9, paragraph 9):
...Scalar types, trivially copyable class types, arrays of such types, and cv-qualified versions of these types are collectively called trivially copyable types....
cv-qualified by definition includes const
and/or volatile
(§3.9.3). It would therefore appear that volatile
values are explicitly trivially copyable, if the unqualified type would be trivially copyable (a scalar or trivially copyable class type, or array thereof).
The answer has been changed by defect reports CWG496 and CWG2094. The latter DR reverts the former.
Now, for a volatile non-static data member,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With