<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 - clang++ accept illegal code"
href="https://bugs.llvm.org/show_bug.cgi?id=37886">37886</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang++ accept illegal code
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</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>enhancement
</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>zhonghao@pku.org.cn
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>The code is as follow:
#include <string>
template <typename T>
struct SimpleAllocator
{
template <typename U> friend struct SimpleAllocator;
using value_type = T;
using pointer = T *;
struct rebind { template <typename U> using other = SimpleAllocator<U>; };
using propagate_on_container_copy_assignment = std::true_type;
using propagate_on_container_move_assignment = std::true_type;
using propagate_on_container_swap = std::true_type;
explicit SimpleAllocator(void * p) : state(p) {}
template <typename U>
SimpleAllocator(SimpleAllocator<U> const & rhs) : state(rhs.state) {}
pointer allocate(std::size_t n)
{
return static_cast<pointer>(::operator new(sizeof(T) * n));
}
void deallocate(pointer p, std::size_t)
{
::operator delete(p);
}
template <typename U, typename V>
friend bool operator==(SimpleAllocator<U> const & lhs, SimpleAllocator<V>
const & rhs)
{
return lhs.state == rhs.state;
}
template <typename U, typename V>
friend bool operator!=(SimpleAllocator<U> const & lhs, SimpleAllocator<V>
const & rhs)
{
return lhs.state != rhs.state;
}
private:
void * state;
};
using astring = std::basic_string<char, std::char_traits<char>,
SimpleAllocator<char>>;
int main()
{
int x, y;
SimpleAllocator<void> a(&x), b(&y);
astring s("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", a);
astring t(std::move(s), b);
}
The code sample comes from <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED FIXED - basic_string leaks memory when move-constructed with unequal allocator"
href="show_bug.cgi?id=20335">https://bugs.llvm.org/show_bug.cgi?id=20335</a>
The latest clang compiles the attached code sample, but gcc produces many
errors.
I reported the problem to gcc:
<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86074">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86074</a>
In this discussion, programmers indicate that clang shall also reject the code.
My report was marked as duplicated with multiple reports:
<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78925">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78925</a>
<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54376">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54376</a>
It said that GCC, EDG, and MSVC all reject the code, but clang++ accepts it.
Shall clang repair the problem?</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>