Skip to main content

Module default_cpp

Module default_cpp 

Source
Expand description

The value a C++ member takes when the stream does not carry it.

Table 9 of DDS-XTypes 1.3, as C++. crate::default_c is the same table as C and crates/wire-probe/src/default.rs as Rust; that last module carries the clause quotations and the reasoning for the three kinds Table 9 does not list. Deliberately a third derivation and not a call into either of the first two: the columns are compared against each other, and a shared helper would make them agree about a mistake.

§Why a function per type and not T{}

Value-initialisation is not Table 9. T{} zeroes a structure’s members, which is right for the integers and wrong for three kinds the corpus reaches:

  • an enumeration whose first literal is not zero — @value(3) on the first enumerator, or a @default_literal naming another one — takes that literal (§7.3.1.2.1.10) and not the pattern zero;
  • a union takes its discriminator’s default and the branch that selects, which no aggregate initialiser reaches;
  • a member with an explicit @default takes the literal its declaration gave it (§7.2.2.4.4.4.9), which is not the type’s value at all.

Beyond that, adapter/cpp.rs emits no member initialisers, so T{} on a class with no user-provided constructor is value-initialisation of members that are themselves classes and zero-initialisation of the scalars — a rule that reads differently for struct S { int a; } and struct S { S2 a; }, and one the C column has no counterpart for. Two columns answering Table 9 by different mechanisms is a divergence no byte comparison shows, because both produce a value.

§What C++ makes easier than C

Storage. A string is a std::string and its Table 9 value is the empty one, with no heap for the caller to have supplied and no failure to report; a sequence<T> is a std::vector<T> and §7.2.2.4.4.4.7’s “zero-length sequence of the same element type” is clear(). The C column’s _length/_buffer pair and its NULL are not here, and neither is C’s array-versus-pointer split in the parameter: a std::array is a value, so every defaulter takes a plain reference.

An @optional member is NULL and nothing else — “Implementations shall not provide a default value in such a case.”

Functions§

cpp_defaulters_called_by
The defaulters decls call, and exactly those.
cpp_defaulters_called_by_excluding
cpp_defaulters_called_by without the types in excluded, whose defaulters are written by hand elsewhere.
cpp_defaulters_over
Build the defaulter for each of types, prototypes first.
default_into
zd_def_<T>(<place>);
defaulter_name
The defaulter function name for a type.
member_default
One member’s default: its @default, or its type’s.
reachable_from
decls without the routines entry does not reach.