8 Expressions [expr]

8.3 Unary expressions [expr.unary]

8.3.3 Sizeof [expr.sizeof]

The sizeof operator yields the number of bytes in the object representation of its operand. The operand is either an expression, which is an unevaluated operand, or a parenthesized type-id. The sizeof operator shall not be applied to an expression that has function or incomplete type, to the parenthesized name of such types, or to a glvalue that designates a bit-field. sizeof(char), sizeof(signed char) and sizeof(unsigned char) are 1. The result of sizeof applied to any other fundamental type is implementation-defined. [Note: In particular, sizeof(bool), sizeof(char16_­t), sizeof(char32_­t), and sizeof(wchar_­t) are implementation-defined.77 end note] [Note: See [intro.memory] for the definition of byte and [basic.types] for the definition of object representation. end note]

When applied to a reference or a reference type, the result is the size of the referenced type. When applied to a class, the result is the number of bytes in an object of that class including any padding required for placing objects of that type in an array. The size of a most derived class shall be greater than zero. The result of applying sizeof to a base class subobject is the size of the base class type.78 When applied to an array, the result is the total number of bytes in the array. This implies that the size of an array of n elements is n times the size of an element.

The sizeof operator can be applied to a pointer to a function, but shall not be applied directly to a function.

The lvalue-to-rvalue, array-to-pointer, and function-to-pointer standard conversions are not applied to the operand of sizeof. If the operand is a prvalue, the temporary materialization conversion is applied.

The identifier in a sizeof... expression shall name a parameter pack. The sizeof... operator yields the number of arguments provided for the parameter pack identifier. A sizeof... expression is a pack expansion. [Example:

template<class... Types>
struct count {
  static const std::size_t value = sizeof...(Types);
};

end example]

The result of sizeof and sizeof... is a constant of type std​::​size_­t. [Note: std​::​size_­t is defined in the standard header <cstddef> ([cstddef.syn], [support.types.layout]). end note]

sizeof(bool) is not required to be 1.

The actual size of a base class subobject may be less than the result of applying sizeof to the subobject, due to virtual base classes and less strict padding requirements on base class subobjects.