[llvm-bugs] [Bug 51993] New: The allocation function shall not be called when existing an erroneous expression in noptr-new-declarator
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Sep 28 02:10:36 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=51993
Bug ID: 51993
Summary: The allocation function shall not be called when
existing an erroneous expression in
noptr-new-declarator
Product: clang
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: C++2a
Assignee: unassignedclangbugs at nondot.org
Reporter: xmh970252187 at gmail.com
CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk
````
struct C{
void* operator new[](std::size_t N) noexcept(false){ // #1
std::cout<<"abc\n";
auto p = malloc(10);
return p;
}
};
int n = -1;
auto ptr = new C[n];
std::cout<< ptr;
delete [] ptr;
````
Clang prints that `#1` is called and the address "ptr" is non-null. According
to [expr.new] p9, the function at `#1` shall not be called, and since the
function has potential throwing specification, the new-expression should
terminate by throwing an exception. The address shall be null.
Example 2:
````cpp
struct C2{
void* operator new[](std::size_t N) noexcept{ // #2
std::cout<<"abc\n";
auto p = malloc(10);
return p;
}
};
int n = -1;
auto ptr = new C2[n];
std::cout<< ptr;
delete [] ptr;
````
Clang calls `#2`, and the address "ptr" is non-null.
--
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/20210928/48d1f13c/attachment.html>
More information about the llvm-bugs
mailing list