Skip to content

DefaultConstructible

Specifies that an instance of the type can be default constructed.

The type T satisfies DefaultConstructible if all following statements and expressions are valid and have their specified effects:

Given

  • u, an expression of type T.

  • u, an lvalue expression of type Key.

Expression/StatementPostcondition
T u;The object u is default-initialized.
T u{};The object u is value-initialized or aggregate-initialized.
T()All resources owned by u are reclaimed, no exceptions are thrown.
T{}A temporary object of type T is value-initialized or aggregate-initialized.

For objects of non-aggregate class type, a public default constructor must be defined (either user-defined or implicitly defined) to satisfy DefaultConstructible.

Non-const objects of non-class object type are always DefaultConstructible.

Const non-class types are not DefaultConstructible.

Const aggregate types are not DefaultConstructible if any of their members is an object of non-class type.

Non-object types (function types, reference types, and the (possibly cv-qualified) type void) as well as the const non-object types are never DefaultConstructible.

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

LWG 724 (C++98)
Link https://cplusplus.github.io/LWG/issues/724.html
Applied to C++98
Behavior as published

the requirements of DefaultConstructible were missing

Correct behavior

added

LWG 2170 (C++98)
Link https://cplusplus.github.io/LWG/issues/2170.html
Applied to C++98
Behavior as published

initialzing an object of a DefaultConstructible type with an empty initializer could only result in value-initialization

Correct behavior

can also lead to aggregate-initialization

std::is_default_constructible
(since C++11)
std::is_trivially_default_constructible
(since C++11)
std::is_nothrow_default_constructible
(since C++11)

checks if a type has a default constructor

(class template)
default_initializable
(since C++20)

specifies that an object of a type can be default constructed

(concept)