This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-11-11


447. Is offsetof type-dependent?

Section: 13.8.3.4  [temp.dep.constexpr]     Status: CD1     Submitter: Mark Mitchell     Date: 7 Jan 2004

[Voted into WP at October 2005 meeting.]

As far as I can tell, the standard doesn't say whether "offsetof(...)" is type-dependent. In the abstract, it shouldn't be -- an "offsetof" expression is always of type "size_t". But the standard doesn't say to what the definition of the macro is, so I don't think one can deduce that it will always be considered non-dependent by a conforming compiler.

John Spicer: (1) I agree that you can't know if offsetof is dependent because you don't know what it expands to. (2) In principle, offsetof should be like sizeof -- it is value-dependent if its argument is type-dependent.

Mark Mitchell: I think we should say that: (a) offsetof is not type-dependent, and (b) offsetof is value dependent iff the first argument is type-dependent

Everyone is using slightly different builtins to implement this functionality, and I don't think that there's any guarantee that they're all behaving the same here.

Notes from the March 2004 meeting:

Note that any such requirement would be in the library section, not core.

Proposed resolution (October, 2004):

  1. At the end of 13.8.3.3 [temp.dep.expr] paragraph 4, add after the list that ends with throw assignment-expression:

    [Note: For the standard library macro offsetof, see 17.2 [support.types]. —end note]
  2. At the end of 13.8.3.4 [temp.dep.constexpr] paragraph 2, add after the list that ends with sizeof(type-id):

    [Note: For the standard library macro offsetof, see 17.2 [support.types]. —end note]
  3. In 17.2 [support.types] paragraph 4, replace

    The macro offsetof accepts a restricted set of type arguments in this International Standard. If type is not a POD structure or a POD union the results are undefined. The result of applying the offsetof macro to a field that is a static data member or a function member is undefined.

    with

    The macro offsetof(type, member-designator) accepts a restricted set of type arguments in this International Standard. If type is not a POD structure or a POD union ( Clause 11 [class]), the results are undefined. The expression offsetof(type, member-designator) is never type-dependent (13.8.3.3 [temp.dep.expr]) and it is value-dependent (13.8.3.4 [temp.dep.constexpr]) if and only if type is dependent. The result of applying the offsetof macro to a field that is a static data member or a function member is undefined.

    [Note: the original wording shown here reflects the resolutions of library issues 306 and 449.]