Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385274

Are volatile data members trivially copyable?

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

Upvotes: 9

Views: 388

Answers (2)

F.v.S.
F.v.S.

Reputation: 522

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

Upvotes: 1

cHao
cHao

Reputation: 86535

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

Upvotes: 2

Related Questions