I am trying to understand the rules that regulate memory initialization in new int and new int(). Some people suggest that the former leaves memory uninitialized, whereas the latter will initialize it to zero (e.g. this question). However, I cannot find these rules in the documentation. C++ reference says the following:
For non-array type, the single object is constructed in the acquired memory area.
- If initializer is absent, the object is default-initialized.
- If initializer is a parenthesized list of arguments, the object is direct-initialized.
- If initializer is a brace-enclosed list of arguments, the object is list-initialized.
First, it's not quite clear from these statements whether new int() corresponds to the absent initializer or the initializer with a parenthesized list of arguments. Is an empty pair of parentheses still a parenthesized list?
Second, neither default-initialization nor direct-initialization seem to initialize the value to zero in this case. Default initialization leaves the value uninitialized unless it's a class type. Direct initialization does not seem to be applicable as it requires a nonempty parenthesized list of expressions or braced-init-lists.
Interestingly enough, for array types C++ reference clearly and explicitly states that
If initializer is an empty pair of parentheses, each element is value-initialized.
But where are the rules for non-array types with an empty parenthesized list?