Title
Definition and usage of structure, POD-struct, POD-union, and POD class
Status
cd1
Section
Clause [11] [class]
Submitter
Alisdair Meredith

Created on 2005-08-10.00:00:00 last changed 161 months ago

Messages

Date: 2007-04-15.00:00:00

[Voted into WP at April, 2007 meeting.]

Date: 2006-04-15.00:00:00

Proposed resolution (April, 2006):

  1. Change Clause 11 [class] paragraph 4 as indicated:

    A structure is a class defined with the class-key struct; its members and base classes (clause 11.7 [class.derived]) are public by default (clause 11.8 [class.access]). A union is a class defined with the class-key union; its members are public by default and it holds only one data member at a time (11.5 [class.union]). [Note: aggregates of class type are described in 9.4.2 [dcl.init.aggr]. —end note] A POD-struct is an aggregate class that has no non-static data members of type non-POD-struct, non-POD-union (or array of such types) or reference, and has no user-declared copy assignment operator and no user-declared destructor. Similarly, a POD-union is an aggregate union that has no non-static data members of type non-POD-struct, non-POD-union (or array of such types) or reference, and has no user-declared copy assignment operator and no user-declared destructor. A POD class is a class that is either a POD-struct or a POD-union. A POD class is an aggregate class that has no non-static data members of non-POD type (or array of such a type) or reference, and has no user-declared copy assignment operator and no user-declared destructor. A POD-struct is a POD class defined with the class-key struct or the class-key class. A POD-union is a POD class defined with the class-key union.
  2. Change 11.8.3 [class.access.base] paragraph 2 as indicated:

    In the absence of an access-specifier for a base class, public is assumed when the derived class is declared defined with the class-key struct and private is assumed when the class is declared defined with the class-key class. [Example:...
  3. Delete the note in 7.6.1.5 [expr.ref] paragraph 4:

    [Note: “class objects” can be structures (11.4 [class.mem]) and unions (11.5 [class.union]). Classes are discussed in clause Clause 11 [class]. —end note]
  4. Change the commentary in the example in 11.4 [class.mem] paragraph 11 as indicated:

    ...an integer, and two pointers to similar structures objects of the same type. Once this definition...

    ...the count member of the structure object to which sp points; s.left refers to the left subtree pointer of the structure object s; and...

  5. Change _N4567_.17.3 [definitions] “iostream class templates” as indicated:

    ...the argument traits is a structure class which defines additional characteristics...
  6. Change 17.6 [support.dynamic] paragraph 4 as indicated:

    If type is not a POD structure or a POD union POD class (clause 9), the results are undefined.
  7. Change the third bullet of Annex B [implimits] paragraph 2 as indicated:

    • Pointer, array, and function declarators (in any combination) modifying an a class, arithmetic, structure, union, or incomplete type in a declaration [256].

  8. Change the nineteenth bullet of Annex B [implimits] paragraph 2 as indicated:

    • Data members in a single class, structure, or union [16 384].

  9. Change the twenty-first bullet of Annex B [implimits] paragraph 2 as indicated:

    • Levels of nested class, structure, or union definitions in a single struct-declaration-list member-specification [256].

  10. Change C.7 [diff.library] paragraph 6 as indicated:

    The C++ Standard library provides 2 standard structures structs from the C library, as shown in Table 126.
  11. Change the last sentence of 6.8 [basic.types] paragraph 10 as indicated:

    Scalar types, POD-struct types, POD-union types POD classes (clause Clause 11 [class]), arrays of such types and cv-qualified versions of these types (6.8.4 [basic.type.qualifier]) are collectively called POD types.

    Drafting note: Do not change 6.8 [basic.types] paragraph 11, because it's a note and the definition of “layout-compatible” is separate for POD-struct and POD-union in 11.4 [class.mem].

(This resolution also resolves issue 327.)

Date: 2020-12-15.00:00:00

There are several problems with the terms defined in Clause 11 [class] paragraph 4:

A structure is a class defined with the class-key struct; its members and base classes (clause 11.7 [class.derived]) are public by default (clause 11.8 [class.access]). A union is a class defined with the class-key union; its members are public by default and it holds only one data member at a time (11.5 [class.union]). [Note: aggregates of class type are described in 9.4.2 [dcl.init.aggr]. —end note] A POD-struct is an aggregate class that has no non-static data members of type non-POD-struct, non-POD-union (or array of such types) or reference, and has no user-declared copy assignment operator and no user-declared destructor. Similarly, a POD-union is an aggregate union that has no non-static data members of type non-POD-struct, non-POD-union (or array of such types) or reference, and has no user-declared copy assignment operator and no user-declared destructor. A POD class is a class that is either a POD-struct or a POD-union.
  1. Although the term structure is defined here, it is used only infrequently throughout the Standard, often apparently inadvertently and consequently incorrectly:

    • 7.6.1.5 [expr.ref] paragraph 4: the use is in a note and is arguably correct and helpful.

    • 11.4 [class.mem] paragraph 11: the term is used (three times) in an example. There appears to be no reason to use it instead of “class,” but its use is not problematic.

    • _N4567_.17.3 [definitions] “iostream class templates:” the traits argument to the iostream class templates is (presumably unintentionally) constrained to be a structure, i.e., to use the struct keyword and not the class keyword in its definition.

    • Annex B [implimits] paragraph 2: the minimum number of declarator operators is given for structures and unions but not for classes defined using the class keyword.

    • Annex B [implimits] paragraph 2: class, structure, and union are used as disjoint terms in describing nesting levels. (The nonexistent nonterminal struct-declaration-list is used, as well.)

    There does not appear to be a reason for defining the term structure. The one reference where it is arguably useful, in the note in 7.6.1.5 [expr.ref], could be rewritten as something like, “'class objects' may be defined using the class, struct, or union class-keys; see clause Clause 11 [class].”

  2. Based on its usage later in the paragraph and elsewhere, “POD-struct” appears to be intended to exclude unions. However, the definition of “aggregate class” in 9.4.2 [dcl.init.aggr] paragraph 1 includes unions. Furthermore, the name itself is confusing, leading to the question of whether it was intended that only classes defined using struct could be POD-structs or if class-classes are included. The definition should probably be rewritten as, “A POD-struct is an aggregate class defined with the class-key struct or the class-key class that has no...

  3. In most references outside clause Clause 11 [class], POD-struct and POD-union are mentioned together and treated identically. These references should be changed to refer to the unified term, “POD class.”

  4. Noted in passing: 17.2 [support.types] paragraph 4 refers to the undefined terms “POD structure” and (unhyphenated) “POD union;” the pair should be replaced by a single reference to “POD class.”

History
Date User Action Args
2008-10-05 00:00:00adminsetstatus: wp -> cd1
2007-08-05 00:00:00adminsetstatus: dr -> wp
2007-05-06 00:00:00adminsetmessages: + msg1505
2007-05-06 00:00:00adminsetstatus: ready -> dr
2006-11-05 00:00:00adminsetstatus: review -> ready
2006-04-22 00:00:00adminsetmessages: + msg1325
2006-04-22 00:00:00adminsetstatus: open -> review
2005-08-10 00:00:00admincreate