for the constructor of a class or struct, every base class sub-object and every non-variant non-static data member must be initialized.(A function body that is = default or =delete contains none of the above.)Ī constexpr constructor whose function body is not =delete must satisfy the following additional requirements: a definition of a variable of static or thread storage duration.a definition of a variable of non-literal type.a definition of a variable for which no initialization is performed.a statement with a label other than case and default.if the function is not a constructor, exactly one return statement.typedef declarations and alias declarations that do not define classes or enumerations.the function body must be either deleted or defaulted or contain only the following:.No diagnostic is required for a violation of this bullet. there exists at least one set of argument values such that an invocation of the function could be an evaluated subexpression of a core constant expression (for constructors, use in a constant initializer is sufficient) (since C++14).its return value (if any) and each of its parameters must be of a LiteralType.for constructor and destructor (since C++20), the class must have no virtual base classes.Such initialization is disallowed in a module interface unit (outside its private-module-fragment, if any) or a module partition, and is deprecated in any other context.Ī constexpr function must satisfy the following requirements: If a constexpr variable is not translation-unit-local, it should not be initialized to point to, or refer to, or have a (possibly recursive) subobject that points to or refers to, a translation-unit-local entity that is usable in constant expressions. it is of class type or (possibly multi-dimensional) array thereof, that class type has a constexpr destructor, and for a hypothetical expression e whose only effect is to destroy the object, e would be a core constant expression if the lifetime of the object and its non-mutable subobjects (but not its mutable subobjects) were considered to start within e.it is not of class type nor (possibly multi-dimensional) array thereof, or.it must have constant destruction, i.e.the full-expression of its initialization, including all implicit conversions, constructors calls, etc, must be a constant expression.If any declaration of a function or function template has a constexpr specifier, then every declaration must contain that specifier.Ī constexpr variable must satisfy the following requirements: A constexpr specifier used in a function or static data member (since C++17) declaration implies inline. Such variables and functions can then be used where only compile time constant expressions are allowed (provided that appropriate function arguments are given).Ī constexpr specifier used in an object declaration or non-static member function (until C++14) implies const. The constexpr specifier declares that it is possible to evaluate the value of the function or variable at compile time.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |