public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/110102] New: [13 regression] initializer_list ctors of containers skip Allocator_traits::construct, copies move-only type
@ 2023-06-03  3:53 arthur.j.odwyer at gmail dot com
  2023-06-03 13:52 ` [Bug c++/110102] [13/14 " redi at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: arthur.j.odwyer at gmail dot com @ 2023-06-03  3:53 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-06-23 17:43 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-03  3:53 [Bug libstdc++/110102] New: [13 regression] initializer_list ctors of containers skip Allocator_traits::construct, copies move-only type arthur.j.odwyer at gmail dot com
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

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).