|
1220 | 1220 | \item any non-static data member with no default member initializer\iref{class.mem} is
|
1221 | 1221 | of reference type,
|
1222 | 1222 |
|
1223 |
| -\item any non-variant non-static data member of const-qualified type |
| 1223 | +\item \tcode{X} is a non-union class and |
| 1224 | +any non-variant non-static data member of const-qualified type |
1224 | 1225 | (or possibly multidimensional array thereof)
|
1225 | 1226 | with no \grammarterm{brace-or-equal-initializer}
|
1226 | 1227 | is not const-default-constructible\iref{dcl.init},
|
1227 | 1228 |
|
1228 |
| -\item \tcode{X} is a union and all of its variant members are of const-qualified |
1229 |
| -type (or possibly multidimensional array thereof), |
1230 |
| - |
1231 |
| -\item \tcode{X} is a non-union class and all members of any anonymous union member are |
1232 |
| -of const-qualified type (or possibly multidimensional array thereof), |
1233 |
| - |
1234 |
| -\item any potentially constructed subobject, except for a non-static data member |
1235 |
| -with a \grammarterm{brace-or-equal-initializer} |
1236 |
| -or a variant member of a union where another non-static data member |
1237 |
| -has a \grammarterm{brace-or-equal-initializer}, |
| 1229 | +\item any non-variant potentially constructed subobject, except for a non-static data member |
| 1230 | +with a \grammarterm{brace-or-equal-initializer}, |
1238 | 1231 | has class type \tcode{M} (or possibly multidimensional array thereof)
|
1239 | 1232 | and overload resolution\iref{over.match}
|
1240 | 1233 | as applied to find \tcode{M}'s corresponding constructor
|
1241 |
| -either does not result in a usable candidate\iref{over.match.general} |
1242 |
| -or, in the case of a variant member, selects a non-trivial function, or |
| 1234 | +does not result in a usable candidate\iref{over.match.general}, or |
1243 | 1235 |
|
1244 |
| -\item any potentially constructed subobject has |
1245 |
| -class type \tcode{M} (or possibly multidimensional array thereof) and |
| 1236 | +\item any potentially constructed subobject $S$ has |
| 1237 | +class type \tcode{M} (or possibly multidimensional array thereof), |
1246 | 1238 | \tcode{M} has
|
1247 | 1239 | a destructor that is deleted or inaccessible from the defaulted default
|
1248 |
| -constructor. |
| 1240 | +constructor, and |
| 1241 | +either $S$ is non-variant or $S$ has a default member initializer. |
1249 | 1242 | \end{itemize}
|
1250 | 1243 |
|
1251 | 1244 | \pnum
|
1252 |
| -A default constructor is |
| 1245 | +A default constructor for a class \tcode{X} is |
1253 | 1246 | \defnx{trivial}{constructor!default!trivial}
|
1254 | 1247 | if it is not user-provided and if
|
1255 | 1248 | \begin{itemize}
|
1256 | 1249 | \item
|
1257 |
| -its class has no virtual functions\iref{class.virtual} and no virtual base |
| 1250 | +\tcode{X} has no virtual functions\iref{class.virtual} and no virtual base |
1258 | 1251 | classes\iref{class.mi}, and
|
1259 | 1252 |
|
1260 |
| -\item no non-static data member of its class has |
| 1253 | +\item no non-static data member of \tcode{X} has |
1261 | 1254 | a default member initializer\iref{class.mem}, and
|
1262 | 1255 |
|
1263 | 1256 | \item
|
1264 |
| -all the direct base classes of its class have trivial default constructors, and |
| 1257 | +all the direct base classes of \tcode{X} have trivial default constructors, and |
1265 | 1258 |
|
1266 | 1259 | \item
|
1267 |
| -for all the non-static data members of its class that are of class |
| 1260 | +either \tcode{X} is a union or |
| 1261 | +for all the non-variant non-static data members of \tcode{X} that are of class |
1268 | 1262 | type (or array thereof), each such class has a trivial default constructor.
|
1269 | 1263 | \end{itemize}
|
1270 | 1264 |
|
1271 | 1265 | Otherwise, the default constructor is
|
1272 | 1266 | \defnx{non-trivial}{constructor!default!non-trivial}.
|
1273 | 1267 |
|
1274 | 1268 | \pnum
|
1275 |
| -An implicitly-defined\iref{dcl.fct.def.default} default constructor performs the set of |
| 1269 | +If a default constructor of a union-like class \tcode{X} is trivial, |
| 1270 | +then for each union \tcode{U} |
| 1271 | +that is either \tcode{X} or an anonymous union member of \tcode{X}, |
| 1272 | +if the first variant member, if any, of \tcode{U} |
| 1273 | +has implicit-lifetime type\iref{basic.types.general}, |
| 1274 | +the default constructor of \tcode{X} begins the lifetime of that member |
| 1275 | +if it is not the active member of its union. |
| 1276 | +\begin{note} |
| 1277 | +It is already the active member if \tcode{U} was value-initialized. |
| 1278 | +\end{note} |
| 1279 | +Otherwise, |
| 1280 | +an implicitly-defined\iref{dcl.fct.def.default} default constructor performs the set of |
1276 | 1281 | initializations of the class that would be performed by a user-written default
|
1277 | 1282 | constructor for that class with no
|
1278 | 1283 | \grammarterm{ctor-initializer}\iref{class.base.init} and an empty
|
|
2022 | 2027 | A defaulted destructor for a class
|
2023 | 2028 | \tcode{X} is defined as deleted if
|
2024 | 2029 | \begin{itemize}
|
2025 |
| -\item any potentially constructed subobject has class type |
2026 |
| - \tcode{M} (or possibly multidimensional array thereof) and |
| 2030 | +\item \tcode{X} is a non-union class and |
| 2031 | + any non-variant potentially constructed subobject has class type |
| 2032 | + \tcode{M} (or possibly multidimensional array thereof) where |
2027 | 2033 | \tcode{M} has a destructor that is deleted or
|
2028 |
| - is inaccessible from the defaulted destructor or, |
2029 |
| - in the case of a variant member, is non-trivial, |
| 2034 | + is inaccessible from the defaulted destructor, |
2030 | 2035 |
|
2031 |
| -\item or, for a virtual destructor, lookup of the non-array deallocation |
| 2036 | +\item |
| 2037 | + \tcode{X} is a union and |
| 2038 | + \begin{itemize} |
| 2039 | + \item |
| 2040 | + overload resolution to select a constructor to |
| 2041 | + default-initialize an object of type \tcode{X} either fails or |
| 2042 | + selects a constructor that is either deleted or not trivial, or |
| 2043 | + \item |
| 2044 | + \tcode{X} has a variant member \tcode{V} of |
| 2045 | + class type \tcode{M} (or possibly multi-dimensional array thereof) |
| 2046 | + where \tcode{V} has a default member initializer and |
| 2047 | + \tcode{M} has a destructor that is non-trivial, or, |
| 2048 | + \end{itemize} |
| 2049 | + |
| 2050 | +\item for a virtual destructor, lookup of the non-array deallocation |
2032 | 2051 | function results in an ambiguity or in a function that is deleted or
|
2033 | 2052 | inaccessible from the defaulted destructor.
|
2034 | 2053 | \end{itemize}
|
2035 | 2054 |
|
2036 | 2055 | \pnum
|
2037 |
| -A destructor is trivial if it is not user-provided and if |
| 2056 | +A destructor for a class \tcode{X} is trivial if it is not user-provided and if |
2038 | 2057 | \begin{itemize}
|
2039 | 2058 | \item the destructor is not virtual,
|
2040 | 2059 |
|
2041 |
| -\item all of the direct base classes of its class have trivial destructors, and |
| 2060 | +\item all of the direct base classes of \tcode{X} have trivial destructors, and |
2042 | 2061 |
|
2043 |
| -\item for all of the non-static data members of its class that are of class |
| 2062 | +\item either \tcode{X} is a union or |
| 2063 | +for all of the non-variant non-static data members of \tcode{X} that are of class |
2044 | 2064 | type (or array thereof), each such class has a trivial destructor.
|
2045 | 2065 | \end{itemize}
|
2046 | 2066 |
|
|
3054 | 3074 | If a union contains a non-static data member of
|
3055 | 3075 | reference type, the program is ill-formed.
|
3056 | 3076 | \begin{note}
|
3057 |
| -Absent default member initializers\iref{class.mem}, |
3058 |
| -if any non-static data member of a union has a non-trivial |
3059 |
| -default constructor\iref{class.default.ctor}, |
3060 |
| -copy constructor, move constructor\iref{class.copy.ctor}, |
3061 |
| -copy assignment operator, move assignment operator\iref{class.copy.assign}, |
3062 |
| -or destructor\iref{class.dtor}, the corresponding member function |
| 3077 | +If any non-static data member of a union has a non-trivial |
| 3078 | +copy constructor, |
| 3079 | +move constructor\iref{class.copy.ctor}, |
| 3080 | +copy assignment operator, or |
| 3081 | +move assignment operator\iref{class.copy.assign}, |
| 3082 | +the corresponding member function |
3063 | 3083 | of the union must be user-provided or it will
|
3064 | 3084 | be implicitly deleted\iref{dcl.fct.def.delete} for the union.
|
3065 | 3085 | \begin{example}
|
|
3072 | 3092 | };
|
3073 | 3093 | \end{codeblock}
|
3074 | 3094 | Since \tcode{std::string}\iref{string.classes} declares non-trivial versions of all of the special
|
3075 |
| -member functions, \tcode{U} will have an implicitly deleted default constructor, |
3076 |
| -copy/move constructor, |
3077 |
| -copy/move assignment operator, and destructor. |
3078 |
| -To use \tcode{U}, some or all of these member functions |
3079 |
| -must be user-provided. |
| 3095 | +member functions, \tcode{U} will have an implicitly deleted |
| 3096 | +copy/move constructor and copy/move assignment operator. |
| 3097 | +The default constructor and destructor of \tcode{U} are both trivial |
| 3098 | +even though \tcode{std::string} has |
| 3099 | +a non-trivial default constructor and a non-trivial destructor. |
3080 | 3100 | \end{example}
|
3081 | 3101 | \end{note}
|
3082 | 3102 |
|
|
0 commit comments