public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "roman at binarylife dot net" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/63322] New: std::atomic<T> where T is not trivially copyable should be disabled.
Date: Sun, 21 Sep 2014 17:24:00 -0000	[thread overview]
Message-ID: <bug-63322-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63322

            Bug ID: 63322
           Summary: std::atomic<T> where T is not trivially copyable
                    should be disabled.
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roman at binarylife dot net

[atomic.types.generic]: There is a generic class template atomic<T>. The type
of the template argument T shall be trivially copyable (3.9).

It would be helpful if std::atomic<T> disallowed wrong T because the generated
code is obviously makes no sense (at least for x86_64): bar() returns a
hard-coded NaN.

$ cat test.cc 
#include <atomic>

long double foo(const long double& f) noexcept;

struct X {
  X() = default;
  X(X const& o) noexcept : f(foo(o.f)) {}
  X& operator=(X const& o) noexcept { f = foo(o.f); return *this; }
  long double f = foo(0);
};

extern std::atomic<X> a;

long double bar() { a.load().f; }

$ g++ -c -O2 --save-temps -std=c++11 test.cc && echo ok
ok

$ cat test.s 
        .file   "test.cc"
        .section        .text.unlikely,"ax",@progbits
.LCOLDB2:
        .text
.LHOTB2:
        .p2align 4,,15
        .globl  _Z3barv
        .type   _Z3barv, @function
_Z3barv:
.LFB330:
        .cfi_startproc
        fldz
        subq    $24, %rsp
        .cfi_def_cfa_offset 32
        movq    %rsp, %rdi
        fstpt   (%rsp)
        call    _Z3fooRKe
        fstp    %st(0)
        movl    $5, %esi
        movl    $a, %edi
        call    __atomic_load_16
        flds    .LC1(%rip)
        addq    $24, %rsp
        .cfi_def_cfa_offset 8
        ret
        .cfi_endproc
.LFE330:
        .size   _Z3barv, .-_Z3barv
        .section        .text.unlikely
.LCOLDE2:
        .text
.LHOTE2:
        .section        .rodata.cst4,"aM",@progbits,4
        .align 4
.LC1:
        .long   2143289344
        .ident  "GCC: (GNU) 5.0.0 20140920 (experimental)"
        .section        .note.GNU-stack,"",@progbits


             reply	other threads:[~2014-09-21 17:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-21 17:24 roman at binarylife dot net [this message]
2014-09-21 18:13 ` [Bug libstdc++/63322] " redi at gcc dot gnu.org
2014-10-09 18:41 ` redi at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-63322-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).