<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - The allocation function shall not be called when existing an erroneous expression in noptr-new-declarator"
href="https://bugs.llvm.org/show_bug.cgi?id=51993">51993</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>The allocation function shall not be called when existing an erroneous expression in noptr-new-declarator
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++2a
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>xmh970252187@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>````
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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>