Consider a 32-bit size_t. Then the new-expression new int[0x1'0000'0000LL] converts the size expression implicitly to std::size_t, which becomes 0, where 0 would not exceed size limits. If it were new int[-0x1'0000'0000LL] (which would convert to 1), it would become invalid via [expr.new]p(8.1).
Suggested resolution:
Modify [expr.new]p8:
the expression is of non-class type and its value before converting to std::size_tis less than zero fits into std::size_t;
the expression is of class type and its value before application of the second standard conversion is less than zero fits into std::size_t;
This should not be too burdensome to compiler vendors since they already check if the number is greater than their limit for object size. It can be implemented by moving the comparison before the conversion to size_t.
Full name of submitter: Mital Ashok
Reference (section label): [expr.new]
Issue description:
Consider a 32-bit
size_t
. Then the new-expressionnew int[0x1'0000'0000LL]
converts the size expression implicitly tostd::size_t
, which becomes0
, where0
would not exceed size limits. If it werenew int[-0x1'0000'0000LL]
(which would convert to1
), it would become invalid via [expr.new]p(8.1).Suggested resolution:
Modify [expr.new]p8:
This should not be too burdensome to compiler vendors since they already check if the number is greater than their limit for object size. It can be implemented by moving the comparison before the conversion to
size_t
.