[llvm-bugs] [Bug 38300] New: Wrong exception deduction for some forms of placement new

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jul 24 17:59:53 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38300

            Bug ID: 38300
           Summary: Wrong exception deduction for some forms of placement
                    new
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zhonghao at pku.org.cn
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

clang version 7.0.0 (trunk 337118) rejects the following program:

//--
#include <new>

int n;

static_assert(!noexcept(::new (std::nothrow) int[n]), "");
//--

Further the following program aborts even though it shouldn't:

//---
#include <new>

extern "C" void abort();

void test_too_small(int n) {
 new (std::nothrow) int[n]{1,2,3,4};
}

int main()
{
  bool f = false;
  try {
    test_too_small(3);
  } catch (...) {
    f = true;
  }
  if (!f)
    abort();
}
//---

Rationale: According to [expr.new] p7:

"[..] if the new-initializer is a bracedinit-list for which the number of
initializer-clauses exceeds the number of elements to initialize, 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
(18.6.2.2)."

I tried g++. It accept both code samples, and the second code sample does not
abort.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180725/04af502c/attachment-0001.html>


More information about the llvm-bugs mailing list