<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 - Default constructors of node-based containers don't construct allocators"
href="https://bugs.llvm.org/show_bug.cgi?id=49332">49332</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Default constructors of node-based containers don't construct allocators
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>11.0
</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>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>maltsevm@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
</td>
</tr></table>
<p>
<div>
<pre>Consider the following code:
<a href="https://godbolt.org/z/Tn73Me">https://godbolt.org/z/Tn73Me</a>
#include <forward_list>
#include <list>
#include <vector>
#include <deque>
#include <set>
#include <unordered_set>
#include <stdio.h>
int n_alloc = 0;
struct alloc : public std::allocator<char> {
alloc() { n_alloc++; };
};
int main(void)
{
std::vector<char, alloc> c1;
printf("n_alloc: %d\n", n_alloc);
std::deque<char, alloc> c2;
printf("n_alloc: %d\n", n_alloc);
std::forward_list<char, alloc> c3;
printf("n_alloc: %d\n", n_alloc);
std::list<char, alloc> c4;
printf("n_alloc: %d\n", n_alloc);
std::set<char, std::less<char>, alloc> c5;
printf("n_alloc: %d\n", n_alloc);
std::unordered_set<char, std::hash<char>, std::equal_to<char>, alloc> c6;
printf("n_alloc: %d\n", n_alloc);
}
In [forwardlist.overview], the default constructor is specified as follows:
forward_list() : forward_list(Allocator()) { }
Similarly for other containers.
So, the expected output of the above program is:
1
2
3
4
5
6
But with libc++ (recent trunk version) the output is:
1
2
2
2
2
2</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>