Title
Too-large value for size in array new
Status
open
Section
7.6.2.8 [expr.new]
Submitter
Mital Ashok

Created on 2024-06-20.00:00:00 last changed 3 months ago

Messages

Date: 2024-06-20.00:00:00

(From submission #560.)

Consider an implementation with a size_t smaller than long long. An implementation should flag too-large values for the size in an array "new", in the same manner it flags negative values. For example:

  int *p = new int[ULLONG_MAX];

Possible resolution:

Change in 7.6.2.8 [expr.new] paragraph 8 as follows:

If the expression in a noptr-new-declarator is present, it is implicitly converted to std::size_t. The value of the expression is invalid if:
  • the expression is of non-class type and its value before converting to std::size_t is less than zero or greater than the maximum value representable as a std::size_t;
  • the expression is of class type and its value before application of the second standard conversion (12.2.4.2.3 [over.ics.user]) [ Footnote: ... ] is less than zero or greater than the maximum value representable as a std::size_t;
  • its value is such that the size of the allocated object would exceed the implementation-defined limit (Annex B); or
  • the new-initializer is a braced-init-list and the number of array elements for which initializers are provided (including the terminating '\0' in a string-literal (5.13.5 [lex.string])) exceeds the number of elements to initialize.
History
Date User Action Args
2024-06-20 00:00:00admincreate