[LLVMbugs] [Bug 18992] New: Can't initialize static std::atomic[2] member of a template class with { ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT }

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Feb 27 09:16:08 PST 2014


http://llvm.org/bugs/show_bug.cgi?id=18992

            Bug ID: 18992
           Summary: Can't initialize static std::atomic[2] member of a
                    template class with { ATOMIC_FLAG_INIT,
                    ATOMIC_FLAG_INIT }
           Product: clang
           Version: 3.4
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: pdimov at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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:

https://svn.boost.org/trac/boost/ticket/9322

g++ 4.8 and MSVC 2013 have no problem with the code.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140227/4b4c4eef/attachment.html>


More information about the llvm-bugs mailing list