Are volatile data members trivially copyable?

风格不统一 提交于 2019-12-09 16:28:19

问题


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:

  • https://groups.google.com/forum/?fromgroups=#!topic/comp.std.c++/5cWxmw71ktI
  • http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48118
  • http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#496

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


回答1:


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



来源:https://stackoverflow.com/questions/13407737/are-volatile-data-members-trivially-copyable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!