This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Why does std::atomic< std::shared_ptr<string> > compile?


Hi there,

I've just had a discussion triggered by the blog post at
http://bert-hubert.blogspot.de/2015/03/some-notes-on-sharedptr-atomicity-and.html,
and in the process, I discovered that this snippet:

#include <atomic>
#include <cstdlib>
#include <memory>
#include <string>

int main(int argc, char **argv) {
  std::atomic< std::shared_ptr<std::string> > my_atomic_shared_pointer;

  return EXIT_SUCCESS;
}

Does, in fact, compile on gcc 4.9.2 (Fedora). However, based on
http://en.cppreference.com/w/cpp/atomic/atomic I would expect this to
error out, since std::shared_ptr is surely not TriviallyCopyable. Can
somebody in the know (jwakely?) comment whether this is supposed to
compile, and would work as implied?

FWIW, as soon as I try to actually do anything with the object, i.e.

my_atomic_shared_pointer = std::make_shared<std::string>("foo");

it fails to link with "undefined reference to `__atomic_store_16'".

Thanks in advance,

Maik Zumstrull


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]