9
votes

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

2
I just spotted that the proposed wording change in issue #496 is only a month or so old and, as such, post-dates C++11. It is therefore still active. I guess then I'm only asking the same question as Maddock started back in 2004 with #496. - Lightness Races in Orbit

2 Answers

2
votes

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).

0
votes

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 the member is of a scalar type or possibly multidimentional array there of, doesn't make the class non-trivially-copyable, however
  • if the member of is of a class type or possibly multidimentional array there of, the implictly declared copy/move functions of the containing class are all deleted, which makes the class non-trivially copyable (since CWG1734).