]> granicus.if.org Git - clang/commit
Fix a rejects-valid in C++11: array new of a negative size, or overflowing array
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 4 Feb 2012 05:35:53 +0000 (05:35 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 4 Feb 2012 05:35:53 +0000 (05:35 +0000)
commit0b458fd8b6321c11e8b22727e0e9b9960e93ff4d
tree04a6de94b2327453bec60c637ee23aa9a8c2345e
parent5b66405c4db92ad3ad37c13454960ebfb807418b
Fix a rejects-valid in C++11: array new of a negative size, or overflowing array
new, is well-formed with defined semantics of throwing (a type which can be
caught by a handler for) std::bad_array_new_length, unlike in C++98 where it is
somewhere nebulous between undefined behavior and ill-formed.

If the array size is an integral constant expression and satisfies one of these
criteria, we would previous the array new expression, but now in C++11 mode, we
merely issue a warning (the code is still rejected in C++98 mode, naturally).

We don't yet implement new C++11 semantics correctly (see PR11644), but we do
implement the overflow checking, and (for the default operator new) convert such
expressions to an exception, so accepting such code now does not seem especially
unsafe.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149767 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExprCXX.cpp
test/SemaCXX/new-delete-cxx0x.cpp [new file with mode: 0644]
test/SemaCXX/new-delete.cpp