<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - attribute visibility problems when using operator overloading (new/delete)"
href="https://llvm.org/bugs/show_bug.cgi?id=25740">25740</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>attribute visibility problems when using operator overloading (new/delete)
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.7
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>kaptain-blaubaer@web.de
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Using this example:
#include <cstdio>
#include <cstdlib>
// replacement of a minimal set of functions:
__attribute__((visibility("hidden")))
void* operator new(std::size_t sz) {
std::printf("global op new called, size = %zu\n",sz);
return std::malloc(sz);
}
void operator delete(void* ptr)
{
std::puts("global op delete called");
std::free(ptr);
}
int main() {
int* p1 = new int;
delete p1;
int* p2 = new int[10]; // guaranteed to call the replacement in C++11
delete[] p2;
}
Compilation fails using CLang 3.7.0 and Clang 3.8.0 (trunk):
$ clang x.cpp -lstdc++
x.cpp:4:16: error: visibility does not match previous declaration
__attribute__((visibility("hidden")))
^
note: previous attribute is here
x.cpp:5:7: warning: 'operator new' is missing exception specification
'throw(std::bad_alloc)'
void* operator new(std::size_t sz) {
^
throw(std::bad_alloc)
x.cpp:9:6: warning: 'operator delete' is missing exception specification
'throw()'
void operator delete(void* ptr)
^
throw()
2 warnings and 1 error generated.
But Succeeds using Clang 3.6.2 and 3.5.0:
$ clang x.cpp -lstdc++
x.cpp:5:7: warning: 'operator new' is missing exception specification
'throw(std::bad_alloc)'
void* operator new(std::size_t sz) {
^
throw(std::bad_alloc)
x.cpp:9:6: warning: 'operator delete' is missing exception specification
'throw()'
void operator delete(void* ptr)
^
throw()
2 warnings generated.</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>