The C++17 Standard says in [support.types.layout]:
Use of the
offsetof
macro with a type other than a standard-layout class is conditionally-supported.
And in [defns.cond.supp]:
conditionally-supported
program construct that an implementation is not required to support
I find this definition of offsetof
not very precise.
Does it mean that I can safely attempt to use this with non standard-layout classes?
How is "conditionally-supported" different from implementation defined?
Is a compiler not supporting offsetof
for a particular type of class required to produce a diagnostic?
Does it mean that I can safely attempt to use this with non standard-layout classes?
If the implementation permits it. Being conditionally supported means this must be documented.
How is "conditionally-supported" different from implementation defined?
To quote the standard on this:
[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"
The key difference is what choice the implementation has. Do it exactly as the standard says, or not at all. Vs. doing it in one of several ways without an option to refuse.
Is a compiler not supporting
offsetof
for a particular type of class required to produce a diagnostic?
If it's a conforming implementation, it will issue a diagnostic ([intro.compliance]/2.2 courtesy of @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."