易失性数据成员是否可以轻易复制? [英] Are volatile data members trivially copyable?

查看:147
本文介绍了易失性数据成员是否可以轻易复制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在撰写这个答案时,我意识到我对我的结论不满意,因为我通常会在碰到发布您的回答

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.

我可以找到几个合理令人信服的引文,认为 volatile 数据成员是不允许的实现定义或禁止扩展:

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

但我无法在标准的 1 特别令人担忧的是,从实际标准的最终措辞中的n3159问题列表中没有建议的措辞改变的迹象。

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.

那么,什么给了? volatile 数据成员是否可以复制?

So, what gives? Are volatile data members trivially copyable, or not?

1 C ++ 11

推荐答案

我看到trivially copyable的定义(C ++ 11§3.9, 9):

I'm seeing the following definition for "trivially copyable" (C++11 §3.9, paragraph 9):


...标量类型,简单可复制类类型,这种类型的数组, 类型的版本。

cv-qualified 包括 const 和/或 volatile (§3.9.3)。因此,如果非限定类型将是简单可复制的(标量或简单可复制类类型或其数组),则 volatile 值显然是可复制的。

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

这篇关于易失性数据成员是否可以轻易复制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆