对于 C++17 中的非标准布局 类,`offsetof` 为 "conditionally-supported" 是什么意思?
What does it mean for `offsetof` to be "conditionally-supported" for non standard-layout classes in C++17?
C++17 标准在 [support.types.layout] 中说:
Use of the offsetof
macro with a type other than a standard-layout class is conditionally-supported.
conditionally-supported
program construct that an implementation is not required to support
我发现 offsetof
的这个定义不是很准确。
这是否意味着我可以安全地尝试将其用于非标准布局 classes?
"conditionally-supported" 与定义的实现有何不同?
编译器是否不支持 offsetof
特定类型的 class 需要生成诊断?
Does it mean that I can safely attempt to use this with non standard-layout classes?
如果实施允许的话。获得有条件的支持意味着必须记录在案。
How is "conditionally-supported" different from implementation defined?
在此引用标准:
[defns.cond.supp] conditionally-supported - "program construct that an implementation is not required to support"
[defns.impl.defined] implementation-defined behavior - "behavior, for a well-formed program construct and correct data, that depends on the implementation and that each implementation documents"
关键区别在于实现的选择。完全按照标准说的去做,或者根本不做。比。以几种方式中的一种来做,没有拒绝的选择。
Is a compiler not supporting offsetof
for a particular type of class required to produce a diagnostic?
如果它是符合标准的实现,它将发出诊断([intro.compliance]/2.2 由@T.C 提供):
"If a program contains a violation of any diagnosable rule or an occurrence of a construct described in this document as “conditionally-supported” when the implementation does not support that construct, a conforming implementation shall issue at least one diagnostic message."
C++17 标准在 [support.types.layout] 中说:
Use of the
offsetof
macro with a type other than a standard-layout class is conditionally-supported.
conditionally-supported
program construct that an implementation is not required to support
我发现 offsetof
的这个定义不是很准确。
这是否意味着我可以安全地尝试将其用于非标准布局 classes?
"conditionally-supported" 与定义的实现有何不同?
编译器是否不支持
offsetof
特定类型的 class 需要生成诊断?
Does it mean that I can safely attempt to use this with non standard-layout classes?
如果实施允许的话。获得有条件的支持意味着必须记录在案。
How is "conditionally-supported" different from implementation defined?
在此引用标准:
[defns.cond.supp] conditionally-supported - "program construct that an implementation is not required to support"
[defns.impl.defined] implementation-defined behavior - "behavior, for a well-formed program construct and correct data, that depends on the implementation and that each implementation documents"
关键区别在于实现的选择。完全按照标准说的去做,或者根本不做。比。以几种方式中的一种来做,没有拒绝的选择。
Is a compiler not supporting
offsetof
for a particular type of class required to produce a diagnostic?
如果它是符合标准的实现,它将发出诊断([intro.compliance]/2.2 由@T.C 提供):
"If a program contains a violation of any diagnosable rule or an occurrence of a construct described in this document as “conditionally-supported” when the implementation does not support that construct, a conforming implementation shall issue at least one diagnostic message."