public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "arthur.j.odwyer at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/110102] New: [13 regression] initializer_list ctors of containers skip Allocator_traits::construct, copies move-only type
Date: Sat, 03 Jun 2023 03:53:54 +0000	[thread overview]
Message-ID: <bug-110102-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 110102
           Summary: [13 regression] initializer_list ctors of containers
                    skip Allocator_traits::construct, copies move-only
                    type
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arthur.j.odwyer at gmail dot com
  Target Milestone: ---

// https://godbolt.org/z/4Gq3TWE6M
#include <list>
struct A {
    A(int) {}
    A(const A&) = delete;
    A(A&&) {}
};
int main() {
    std::list<A> v = {1,2,3};
}

This should be ill-formed, but GCC 13.1 accepts it!
GCC 12.3 and earlier correctly reject it.

This is supposed to be constructing a std::initializer_list<A> and calling
`list::list(initializer_list<A>)`, which should then complain because `A(const
A&)` is deleted.

My guess as to what's happening here:
- We're definitely calling list(initializer_list<A>)
- It's calling _M_range_initialize(il.begin(), il.end())
- That's calling __uninitialized_copy_a
- That's probably somehow deciding that because `A` is trivially copyable, we
can just memcpy it. I.e. bug #89164 redux.

Even if it were copyable, we still wouldn't be allowed to bypass
`allocator_traits::construct`. The above snippet uses std::allocator, but I
originally found a more complicated case with pmr::polymorphic_allocator:

// https://godbolt.org/z/ToT6dW5dM
#include <cstdio>
#include <memory_resource>
#include <vector>
struct Widget {
    using allocator_type = std::pmr::polymorphic_allocator<Widget>;
    Widget(int i) : i_(i) {}
    explicit Widget(int i, allocator_type) : i_(i) {}
    explicit Widget(const Widget& rhs, allocator_type) : i_(rhs.i_ + 100) {}
    int i_;
};
static_assert(std::is_trivially_copyable_v<Widget>);
int main() {
    std::pmr::vector<Widget> v = {1,2,3};
    printf("%d %d %d\n", v[0].i_, v[1].i_, v[2].i_);
}

My understanding is that this should print "101 102 103", as GCC 12 does. But
GCC 13.1 prints "1 2 3" instead.

             reply	other threads:[~2023-06-03  3:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-03  3:53 arthur.j.odwyer at gmail dot com [this message]
2023-06-03 13:52 ` [Bug c++/110102] [13/14 " redi at gcc dot gnu.org
2023-06-04  3:43 ` jason at gcc dot gnu.org
2023-06-04  9:14 ` redi at gcc dot gnu.org
2023-06-04 13:40 ` arthur.j.odwyer at gmail dot com
2023-06-05  6:40 ` rguenth at gcc dot gnu.org
2023-06-05 18:57 ` jason at gcc dot gnu.org
2023-06-05 19:28 ` arthur.j.odwyer at gmail dot com
2023-06-09 15:41 ` cvs-commit at gcc dot gnu.org
2023-06-09 15:52 ` [Bug c++/110102] [13 " jason at gcc dot gnu.org
2023-06-10 12:41 ` arthur.j.odwyer at gmail dot com
2023-06-23  9:42 ` rguenth at gcc dot gnu.org
2023-06-23 16:43 ` cvs-commit at gcc dot gnu.org
2023-06-23 17:43 ` jason 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-110102-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).