<html>
<head>
<base href="http://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 --- - Can't initialize static std::atomic[2] member of a template class with { ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT }"
href="http://llvm.org/bugs/show_bug.cgi?id=18992">18992</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Can't initialize static std::atomic[2] member of a template class with { ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT }
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.4
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</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>pdimov@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>In the following code, which is a simplified version of a Boost header,
#include <atomic>
static std::atomic_flag v[ 2 ] = { ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT };
template< int I > class spinlock_pool
{
public:
static std::atomic_flag pool_[ 2 ];
};
template< int I > std::atomic_flag spinlock_pool< I >::pool_[ 2 ] = {
ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT };
int main()
{
spinlock_pool<1>::pool_[ 0 ];
}
the initialization of v succeeds, but the initialization of pool_ fails with
the following:
C:\Projects\testbed>clang++ -std=c++11 testbed.cpp
testbed.cpp:16:29: warning: expression result unused [-Wunused-value]
spinlock_pool<1>::pool_[ 0 ];
~~~~~~~~~~~~~~~~~~~~~~~ ~ ^
testbed.cpp:12:71: error: call to deleted constructor of 'std::atomic_flag'
...spinlock_pool< I >::pool_[ 2 ] = { ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT };
^~~~~~~~~~~~~~~~
c:/MinGW/lib/gcc/mingw32/4.8.1/include/c++\bits/atomic_base.h:268:26: note:
expanded from macro 'ATOMIC_FLAG_INIT'
#define ATOMIC_FLAG_INIT { 0 }
^~~
testbed.cpp:16:20: note: in instantiation of static data member
'spinlock_pool<1>::pool_' requested here
spinlock_pool<1>::pool_[ 0 ];
^
c:/MinGW/lib/gcc/mingw32/4.8.1/include/c++\bits/atomic_base.h:275:5: note:
function has been explicitly marked deleted here
atomic_flag(const atomic_flag&) = delete;
^
testbed.cpp:12:89: error: call to deleted constructor of 'std::atomic_flag'
...spinlock_pool< I >::pool_[ 2 ] = { ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT };
^~~~~~~~~~~~~~~~
c:/MinGW/lib/gcc/mingw32/4.8.1/include/c++\bits/atomic_base.h:268:26: note:
expanded from macro 'ATOMIC_FLAG_INIT'
#define ATOMIC_FLAG_INIT { 0 }
^~~
c:/MinGW/lib/gcc/mingw32/4.8.1/include/c++\bits/atomic_base.h:275:5: note:
function has been explicitly marked deleted here
atomic_flag(const atomic_flag&) = delete;
^
1 warning and 2 errors generated.
I'm testing with LLVM 3.4 on Windows, but the problem has been originally
reported against "Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM
3.3svn)" here:
<a href="https://svn.boost.org/trac/boost/ticket/9322">https://svn.boost.org/trac/boost/ticket/9322</a>
g++ 4.8 and MSVC 2013 have no problem with the code.</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>