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

2014-04-16 Thread kjell.hedstrom at logrhythm dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60867

Bug ID: 60867
   Summary: std::atomic> 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 is OK for T's that are not trivial to copy.  Example
std::atomic> should fail to g++ compile but is succeeds.

Example: 
std::atomic> 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 
#include 
#include 
#include 


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


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

   //typedef std::unique_ptr 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;
}


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

2014-04-17 Thread kjell.hedstrom at logrhythm dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60867

--- Comment #2 from Kjell Hedstrom  ---
Sounds good. 

>> the error is in your code not the library

Yes. Code like that is obviously faulty. I am happy that you are considering
putting in a static_assert. From a coders perspective I find it very helpful if
the compiler would immediately find bugs of this nature. 

Cheers
Kjell