int* primes = new (nothrow) int[amount]; uses the default initialization, which for int scalars is noop (i.e., the actual initialization is not performed).
If you need explicit initialization, use value initialization instead:
int* primes = new (nothrow) int[amount]();
From the C ++ 11 standard, §8.5 / 6:
To initialize by default an object of type T means:
- If
T is a (possibly cv-qualified) class type, the default constructor for T is called (and initialization is poorly formed if T does not have an available default constructor); - if
T is an array type, each element is initialized by default ; - otherwise, initialization fails .
If the program calls the default initialization of an object of type const-type T , T must be a class type with a user-supplied default constructor.
§8.5 / 7:
To initialize a value of an object of type T means:
- If
T is a class of a class (possibly cv-qualit) with a user-provided constructor, then the default constructor for T is called (and initialization is poorly formed if T does not have an available default constructor); - if
T is a (possibly cv-qualified) non-unit class without a constructor provided by the user, then the object is initialized to zero and if T s the implicitly declared default constructor is nontrivial, this constructor is called. - if
T is an array type, then each element is initialized with a value ; - otherwise, the object is initialized to zero .
An object initialized by initializing a value is considered constructed and, therefore, obeys the provisions of this International Standard that apply to “constructed” objects, objects “for which the constructor is completed,” etc., even if the constructor is not called to initialize the objects.
§8.5 / 6:
For zero initialization of an object or reference of type T means:
- if
T is a scalar type, the object is set to 0 (zero), taken as an integral constant expression converted to T ; - if
T is a (possibly cv-qualified) non-unit class, each non-static data element and each sub-object of the base class are initialized with zeros, and padding is initialized with zero bits; - if
T is a (possibly cv-qualified) join type, the objects of the first non-static named data element are initialized to zero and padding is initialized to zero bits; - if
T is an array type, each element is initialized to zero ; - If
T is a reference type, initialization is not performed.
And finally, from § 8.5 / 10:
An object whose initializer is an empty set of brackets, i.e. () must be initialized with a value.
(All my attention.)
source share