[Bug libstdc++/60867] New: std::atomic<std::unique_ptr<T>> should fail to compile since unique_ptr is not trivial to copy

kjell.hedstrom at logrhythm dot com gcc-bugzilla@gcc.gnu.org
Wed Apr 16 19:52:00 GMT 2014


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60867

            Bug ID: 60867
           Summary: std::atomic<std::unique_ptr<T>> should fail to compile
                    since unique_ptr is not trivial to copy
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kjell.hedstrom at logrhythm dot com

Created attachment 32621
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32621&action=edit
main.ii compiled with:  g++ -v -save-temps  -std=c++11  -O2 -Wall -Wextra
-pthread  main.cpp

std::atomic<T> is OK for T's that are not trivial to copy.  Example
std::atomic<std::unique_ptr<T>> should fail to g++ compile but is succeeds.

Example: 
std::atomic<std::unique_ptr<int>> a;

Expected output is a compilation error. Maybe something similar to what you
would get from clang 3.4   Ref:
http://coliru.stacked-crooked.com/view?id=eb48cd3c29b3be15


See attachment main.cpp with code example. It can be build with no problems
g++ -std=c++11  -O2 -Wall -Wextra -pedantic -pthread -pedantic-errors  main.cpp

the main.ii File was created with:
g++ -v -save-temps  -std=c++11  -O2 -Wall -Wextra -pthread  main.cpp


gcc -v gives:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/probe/libexec/gcc/x86_64-linux-gnu/4.8.2/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../gcc-4.8.2/configure -build=x86_64-linux-gnu
--prefix=/usr/local/probe --enable-cxx-flags='-L/usr/local/probe/lib
-L/usr/local/probe/lib64 -Wl,-rpath -Wl,/usr/local/probe/lib64 -Wl,-rpath
-Wl,/usr/local/probe/lib ' --enable-c-flags='-L/usr/local/probe/lib
-L/usr/local/probe/lib64 -Wl,-rpath -Wl,/usr/local/probe/lib64 -Wl,-rpath
-Wl,/usr/local/probe/lib ' --enable-shared --enable-threads=posix
--enable-libstdcxx-time=rt --enable-checking=release --with-multilib-list=m64
--with-mpc=/usr/local/probe --enable-gather-detailed-mem-stats
--enable-vtable-verify --with-mpc=/usr/local/probe/ --enable-languages=c,c++
Thread model: posix
gcc version 4.8.2 (GCC)


// Only one attachment could be added so the main.cpp is pasted in
// --- main.cpp ---
#include <iostream>
#include <atomic>
#include <memory>
#include <string>


int main() {
  std::atomic<std::unique_ptr<int>> a;  // this line should fail to compile.


   a.store(std::unique_ptr<int>(new int{5}));
   for (size_t index = 0; index < 100; ++index){
      a.load();       
   }

   //typedef std::unique_ptr<int> IntPtr;
   // Hint: using gcc's internal 'has_trivial_copy' shows that it is NOT 
   // trivial to copy
   //std::cout << "Is copyable " << __has_trivial_copy(IntPtr)
   return 0;
}



More information about the Gcc-bugs mailing list