| Start |
|---|
| Value of an out-of-range enum If a scoped enum is converted to an integral type that is too small to hold its value, the resulting value is unspecified. Example: Also, if an integer is converted to an enum and the integer's value is outside the range of the enum's values, the resulting value is unspecified. Example: However, in the next example, the behavior is not unspecified, since the source value is within the range of the enum, although it is unequal to all enumerators: Here |
| Evaluation order of function arguments If a function has multiple arguments, it is unspecified what order they are evaluated in. The following code could print In C++17, the order of evaluation of function arguments remains unspecified. However, each function argument is completely evaluated, and the calling object is guaranteed evaluated before any function arguments are. this must print: or it may not print or similar. Prior to C++17 printing |
| Result of some reinterpret_cast conversions The result of a The result of a However, with most compilers, this was equivalent to |
| Space occupied by a reference A reference is not an object, and unlike an object, it is not guaranteed to occupy some contiguous bytes of memory. The standard leaves it unspecified whether a reference requires any storage at all. A number of features of the language conspire to make it impossible to portably examine any storage the reference might occupy:
In practice, in some cases a reference variable may be implemented similarly to a pointer variable and hence occupy the same amount of storage as a pointer, while in other cases a reference may occupy no space at all since it can be optimized out. For example, in: the compiler is free to simply treat |
| Moved-from state of most standard library classes All standard library containers are left in a valid but unspecified state after being moved from. For example, in the following code, Some classes do have a precisely defined moved-from state. The most important case is that of |
| Order of initialization of globals across TU Whereas inside a Translation Unit, order of initialization of global variables is specified, order of initialization across Translation Units is unspecified. So program with following files might produce as output: or That may lead to Static Initialization Order Fiasco. |
| Static cast from bogus void* value If a The value of |
| Result of some pointer comparisons If two pointers are compared using RemarksIf the behavior of a construct is unspecified, then the standard places some constraints on the behavior, but leaves some freedom to the implementation, which is not required to document what happens in a given situation. It contrasts with implementation-defined behavior (opens new window), in which the implementation is required to document what happens, and undefined behavior, in which anything can happen. |
Read Article
https://develop.horje.com/learn/1434/reference