<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 - thread_local data member of a class template is constructed on each access when the argument is a local structure"
href="https://bugs.llvm.org/show_bug.cgi?id=32557">32557</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>thread_local data member of a class template is constructed on each access when the argument is a local structure
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>4.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>C++11
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>shtaale@vivcourt.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Dear Sir/Madam,
This is a bug for Clang 4.0.0. The version 3.9.1 and earlier seem OK.
The source code working wrong:
#include <iostream>
struct A {
int x = 1;
A() { std::cout << "A::A" << std::endl; }
~A() { std::cout << "A::~A" << std::endl; }
};
template<class T>
struct B {
static thread_local A a;
};
template<class T>
thread_local A B<T>::a;
int main(void) {
struct X {};
std::cout << "main" << std::endl;
int y = 0;
for (int i = 0; i < 3; i++)
y += B<X>::a.x;
std::cout << "y: " << y << std::endl;
std::cout << "main-exit" << std::endl;
}
It is expected to output:
main
A::A
y: 3
main-exit
A::~A
or
A::A
main
y: 3
main-exit
A::~A
Both would be OK from the standard PoV. The version 3.9.1 produces the 1st one.
But the version 4.0.0 produces:
main
A::A
A::A
A::A
y: 3
main-exit
A::~A
A::~A
A::~A
And this is very wrong. I.e. the constructor is called for the same object 3
times, followed by destructing the same object again 3 times.
Thanks
Regards
Alexander Shtannikov
Software developer
Vivienne Court Trading</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>