Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.


Defines a Dsymbol representing an aggregate, which is a struct, union or class.

Specification Structs, Unions, Class.


Source aggregate.d

enum ClassKind: ubyte;
The ClassKind enum is used in AggregateDeclaration AST nodes to specify the linkage type of the struct/class/interface or if it is an anonymous class. If the class is anonymous it is also considered to be a D class.
the aggregate is a d(efault) class
the aggregate is a C++ struct/class/interface
the aggregate is an Objective-C class/interface
the aggregate is a C struct
@safe const(char)* ClassKindToChars(ClassKind c);
Give a nice string for a class kind for error messages
ClassKind c class kind
0-terminated string for c
struct MangleOverride;
If an aggregate has a pargma(mangle, ...) this holds the information to mangle.
abstract class AggregateDeclaration: dmd.dsymbol.ScopeDsymbol;
Abstract aggregate as a common ancestor for Class- and StructDeclaration.
Type type;
StorageClass storage_class;
uint structsize;
size of struct
uint alignsize;
size of struct for alignment purposes
VarDeclarations fields;
VarDeclaration fields
Dsymbol deferred;
any deferred semantic2() or semantic3() symbol
ClassKind classKind;
specifies whether this is a D, C++, Objective-C or anonymous struct/class/interface
CPPMANGLE cppmangle;
Specify whether to mangle the aggregate as a class or a struct This information is used by the MSVC mangler Only valid for class and struct. TODO: Merge with ClassKind ?
MangleOverride* pMangleOverride;
overridden symbol with pragma(mangle, "...") if not null
Dsymbol enclosing;
!=null if is nested pointing to the dsymbol that directly enclosing it.
  1. The function that enclosing it (nested struct and class)
  2. The class that enclosing it (nested class only)
  3. If enclosing aggregate is template, its enclosing dsymbol.
See AggregateDeclaraton::makeNested for the details.
VarDeclaration vthis;
'this' parameter if this aggregate is nested
VarDeclaration vthis2;
'this' parameter if this aggregate is a template and is nested
FuncDeclarations invs;
Array of invariants
FuncDeclaration inv;
Merged invariant calling all members of invs
Dsymbol ctor;
CtorDeclaration or TemplateDeclaration
CtorDeclaration defaultCtor;
default constructor - should have no arguments, because it would be stored in TypeInfo_Class.defaultConstructor
AliasThis aliasthis;
forward unresolved lookups to aliasthis
DtorDeclarations userDtors;
user-defined destructors (~this()) - mixins can yield multiple ones
DtorDeclaration aggrDtor;
aggregate destructor calling userDtors and fieldDtor (and base class aggregate dtor for C++ classes)
DtorDeclaration dtor;
the aggregate destructor exposed as __xdtor alias
DtorDeclaration tidtor;
(same as aggrDtor, except for C++ classes with virtual dtor on Windows)
aggregate destructor used in TypeInfo (must have extern(D) ABI)
DtorDeclaration fieldDtor;
function destructing (non-inherited) fields
Expression getRTInfo;
pointer to GC info generated by object.RTInfo(this)
Visibility visibility;
bool noDefaultCtor;
no default construction
bool disableNew;
disallow allocations using new
Sizeok sizeok;
set when structsize contains valid data
Scope* newScope(Scope* sc);
Create a new scope from sc. semantic, semantic2 and semantic3 will use this for aggregate members.
final size_t nonHiddenFields();
The total number of fields minus the number of hidden fields.
final bool determineSize(const ref Loc loc);
Collect all instance fields, then determine instance size.
false if failed to determine the size.
final bool checkOverlappedFields();
Calculate field[i].overlapped and overlapUnsafe, and check that all of explicit field initializers have unique memory space on instance.
true if any errors happen.
final bool fill(const ref Loc loc, ref Expressions elements, bool ctorinit);
Fill out remainder of elements[] with default initializers for fields[].
Loc loc location
Expressions elements explicit arguments which given to construct object.
bool ctorinit true if the elements will be used for default initialization.
false if any errors occur. Otherwise, returns true and the missing arguments will be pushed in elements[].
final void setDeprecated();
Flag this aggregate as deprecated
final const bool isNested();
Returns true if there's an extra member which is the 'this' pointer to the enclosing context (enclosing aggregate or function)
final Dsymbol searchCtor();
Look for constructor declaration.
void* sinit;
initializer symbol
int apply(Dsymbol symbol, int function(Dsymbol, void*) fp, void* ctx);
Iterate this dsymbol or members of this scoped dsymbol, then call fp with the found symbol and params.
Dsymbol symbol the dsymbol or parent of members to call fp on
int function(Dsymbol, void*) fp function pointer to process the iterated symbol. If it returns nonzero, the iteration will be aborted.
void* ctx context parameter passed to fp.
nonzero if the iteration is aborted by the return value of fp, or 0 if it's completed.
pure nothrow @safe uint alignmember(structalign_t alignment, uint memalignsize, uint offset);
Do byte or word alignment as necessary. Align sizes of 0, as we may not know array sizes yet.
structalign_t alignment struct alignment that is in effect
uint memalignsize natural alignment of field
uint offset offset to be aligned
aligned offset
pure nothrow @safe uint placeField(ref uint nextoffset, uint memsize, uint memalignsize, structalign_t alignment, ref uint aggsize, ref uint aggalignsize, bool isunion);
Place a field (mem) into an aggregate (agg), which can be a struct, union or class
uint nextoffset location just past the end of the previous field in the aggregate. Updated to be just past the end of this field to be placed, i.e. the future nextoffset
uint memsize size of field
uint memalignsize natural alignment of field
structalign_t alignment alignment in effect for this field
uint aggsize size of aggregate (updated)
uint aggalignsize alignment of aggregate (updated)
bool isunion the aggregate is a union
aligned offset to place field at