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_literalnaming 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
@defaulttakes 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
declscall, and exactly those. - cpp_
defaulters_ called_ by_ excluding cpp_defaulters_called_bywithout the types inexcluded, 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 declswithout the routinesentrydoes not reach.