llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

clang should throw `std::bad_array_new_length` when the allocation size for new overflows

Open efriedma-quic opened this issue 14 years ago • 7 comments

Bugzilla Link 11644
Version unspecified
OS All
CC @AaronBallman,@DougGregor,@emaste,@miyuki

Extended Description

C++11 has a new exception type: std::bad_array_new_length. And per the standard,

If the value of that expression is less than zero or such that the size of the allocated object would exceed the implementation-defined limit, no storage is obtained and the new-expression terminates by throwing an exception of a type that would match a handler (15.3) of type std::bad_array_new_length.

Our current behavior is likely good enough in most cases, but it isn't strictly compliant.

efriedma-quic avatar Dec 23 '11 02:12 efriedma-quic

mentioned in issue llvm/llvm-bugzilla-archive#35573

TNorthover avatar Nov 27 '21 00:11 TNorthover

Reopening as this commit was reverted due to runtime support issues.

AaronBallman avatar Aug 28 '14 23:08 AaronBallman

Fixed in r216675

AaronBallman avatar Aug 28 '14 18:08 AaronBallman

Ignore the last comment please, pasted into wrong tab :(

llvmbot avatar May 12 '14 07:05 llvmbot

r208386 gives:

test.cpp:2:13: warning: expression result unused [-Wunused-value]
  return (0 && ({lbl1:lbl2: 0;})), (long)&&lbl1 - (long)&&lbl2;
          ~ ^  ~~~~~~~~~~~~~~~~~
test.cpp:1:16: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
constexpr long a() {
               ^
test.cpp:2:36: note: cast that performs the conversions of a reinterpret_cast is not allowed in a
      constant expression
  return (0 && ({lbl1:lbl2: 0;})), (long)&&lbl1 - (long)&&lbl2;
                                   ^

Is this bug report still valid?

llvmbot avatar May 12 '14 03:05 llvmbot

Related CWG issues and papers:

As __cxa_throw_bad_array_new_length were implemented later (eb7c1a6e50a6790cf498dc44ccb63ba1dc7447e2), is this unblocked now? @AaronBallman

frederick-vs-ja avatar Jan 03 '25 08:01 frederick-vs-ja

@llvm/issue-subscribers-clang-frontend

Author: Eli Friedman (efriedma-quic)

| | | | --- | --- | | Bugzilla Link | [11644](https://llvm.org/bz11644) | | Version | unspecified | | OS | All | | CC | @AaronBallman,@DougGregor,@emaste,@miyuki |

Extended Description

C++11 has a new exception type: std::bad_array_new_length. And per the standard, > If the value of that expression is less than zero or such that the size of the allocated object would exceed the implementation-defined limit, no storage is obtained and the new-expression terminates by throwing an exception of a type that would match a handler (15.3) of type std::bad_array_new_length.

Our current behavior is likely good enough in most cases, but it isn't strictly compliant.

llvmbot avatar Jan 03 '25 08:01 llvmbot