From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 347033858D33; Tue, 31 Jan 2023 20:21:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 347033858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675196476; bh=DSncXLYaQk3L5yExzmDXFhVR1z2Yp/55Dh1r7VCpHvE=; h=From:To:Subject:Date:From; b=eQ/x5TavLVLoPPcYdhqOnRoTNP8Z0Ewfpsbz8yYum5vb3PCm1n1MEnrB9BvMwjDEV DSpLOM0Afx2GG+I4EuEUErUWeK7RYlq4L2/LfWVnxBg8v+GNFOJQGEquZtpAed2Feu VmRO8nWoR87zTY98qldA/ko+MCzVwtNdZVxoh0f8= From: "gccbugzilla at thepirate42 dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/108619] New: Compilation error if the construct method of the allocator isn't implemented and the detructor of value_type is private Date: Tue, 31 Jan 2023 20:21:14 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 12.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gccbugzilla at thepirate42 dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108619 Bug ID: 108619 Summary: Compilation error if the construct method of the allocator isn't implemented and the detructor of value_type is private Product: gcc Version: 12.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: gccbugzilla at thepirate42 dot org Target Milestone: --- When I try to compile this code: #include #include #include class a { ~a() =3D default; friend class b; }; class b { template struct alloc : std::allocator { template void destroy(U* p){ if constexpr (std::is_array_v){ for(auto& elem : *p){ (destroy)(std::addressof(elem)); } } else { p->~U(); } } }; std::vector> v; public: void f(){ v.emplace_back(); } }; with this command line g++ -v -Wall -Wextra -Wpedantic -std=3Dc++20 test.cpp I get this output: Using built-in specs. COLLECT_GCC=3Dg++ COLLECT_LTO_WRAPPER=3D/usr/lib/gcc/x86_64-pc-linux-gnu/12.2.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --enable-languages=3Dc,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-boots= trap --prefix=3D/usr --libdir=3D/usr/lib --libexecdir=3D/usr/lib --mandir=3D/usr= /share/man --infodir=3D/usr/share/info --with-bugurl=3Dhttps://bugs.archlinux.org/ --with-build-config=3Dbootstrap-lto --with-linker-hash-style=3Dgnu --with-system-zlib --enable-__cxa_atexit --enable-cet=3Dauto --enable-checking=3Drelease --enable-clocale=3Dgnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-obj= ect --enable-libstdcxx-backtrace --enable-link-serialization=3D1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=3Dposix --disable-libssp --disable-libstdc= xx-pch --disable-werror Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.2.1 20230111 (GCC)=20 COLLECT_GCC_OPTIONS=3D'-v' '-Wall' '-Wextra' '-Wpedantic' '-std=3Dc++20' '-shared-libgcc' '-mtune=3Dgeneric' '-march=3Dx86-64' '-dumpdir' 'a-' /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.1/cc1plus -quiet -v -D_GNU_SOURCE test.cpp -quiet -dumpdir a- -dumpbase test.cpp -dumpbase-ext .cpp -mtune=3Dgeneric -march=3Dx86-64 -Wall -Wextra -Wpedantic -std=3Dc++20 -ver= sion -o /tmp/ccZ8wizU.s GNU C++20 (GCC) version 12.2.1 20230111 (x86_64-pc-linux-gnu) compiled by GNU C version 12.2.1 20230111, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP GGC heuristics: --param ggc-min-expand=3D100 --param ggc-min-heapsize=3D131= 072 ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-linux-gnu/12.2.1/../../../../x86_64-pc-linux-gnu/in= clude" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.1/../../../../include/c++/12.2.1 /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.1/../../../../include/c++/12.2.1/x86_= 64-pc-linux-gnu /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.1/../../../../include/c++/12.2.1/back= ward /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.1/include /usr/local/include /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.1/include-fixed /usr/include End of search list. GNU C++20 (GCC) version 12.2.1 20230111 (x86_64-pc-linux-gnu) compiled by GNU C version 12.2.1 20230111, GMP version 6.2.1, MPFR version 4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP GGC heuristics: --param ggc-min-expand=3D100 --param ggc-min-heapsize=3D131= 072 Compiler executable checksum: d14869452663722b786a6617dcf7b0b2 In file included from /usr/include/c++/12.2.1/vector:70, from test.cpp:2: /usr/include/c++/12.2.1/bits/vector.tcc: In instantiation of =E2=80=98const= expr std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args =3D {}; _Tp =3D a; _Alloc =3D b::alloc; reference =3D a&]=E2=80=99: test.cpp:36:23: required from here /usr/include/c++/12.2.1/bits/vector.tcc:117:37: error: no matching function= for call to =E2=80=98__gnu_cxx::__alloc_traits, a>::construct(std::_Vector_base >::_Vector_impl&, a*&)=E2=80= =99 117 | _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, |=20=20=20=20=20=20=20=20=20=20=20=20 ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 118 | std::forward<_Args>(__args)...= ); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/12.2.1/ext/alloc_traits.h:34, from /usr/include/c++/12.2.1/bits/stl_uninitialized.h:64, from /usr/include/c++/12.2.1/memory:65, from test.cpp:1: /usr/include/c++/12.2.1/bits/alloc_traits.h:360:9: note: candidate: =E2=80=98template static constexpr decltype (std::allocator_traits< >::_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits< >::construct::__args)...)) std::allocator_traits< >::construct(_Alloc&, _Tp*, _Args&& ...) [with _Args =3D _Tp; _Alloc =3D b::alloc]=E2=80=99 360 | construct(_Alloc& __a, _Tp* __p, _Args&&... __args) | ^~~~~~~~~ /usr/include/c++/12.2.1/bits/alloc_traits.h:360:9: note: template argument deduction/substitution failed: /usr/include/c++/12.2.1/bits/alloc_traits.h: In substitution of =E2=80=98te= mplate static constexpr decltype (std::allocator_traits >::_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits< >::construct::__args)...)) std::allocator_traits >::construct(b::alloc&, _Tp*, _Args&& ...) [with _Tp =3D a; _Args =3D {}= ]=E2=80=99: /usr/include/c++/12.2.1/bits/vector.tcc:117:30: required from =E2=80=98co= nstexpr std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args =3D {}; _Tp =3D a; _Alloc =3D b::alloc; reference =3D a&]=E2=80=99 test.cpp:36:23: required from here /usr/include/c++/12.2.1/bits/alloc_traits.h:363:33: error: no matching func= tion for call to =E2=80=98std::allocator_traits >::_S_construct(b::a= lloc&, a*&)=E2=80=99 363 | -> decltype(_S_construct(__a, __p, std::forward<_Args>(__args)...)) |=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/12.2.1/bits/alloc_traits.h:249:9: note: candidate: =E2=80=98template static constexpr std::_Requir= e >::__construct_helper<_Tp, _Args>::type> std::allocator_traits< >::_S_construct(_Alloc&, _Tp*, _Args&& ...) [with _Args =3D _Tp; _Alloc =3D b::alloc]=E2=80=99 249 | _S_construct(_Alloc& __a, _Tp* __p, _Args&&... __args) | ^~~~~~~~~~~~ /usr/include/c++/12.2.1/bits/alloc_traits.h:249:9: note: template argument deduction/substitution failed: In file included from /usr/include/c++/12.2.1/bits/move.h:57, from /usr/include/c++/12.2.1/bits/new_allocator.h:36, from /usr/include/c++/12.2.1/x86_64-pc-linux-gnu/bits/c++allocator.h:33, from /usr/include/c++/12.2.1/bits/allocator.h:46, from /usr/include/c++/12.2.1/memory:63: /usr/include/c++/12.2.1/type_traits: In substitution of =E2=80=98template using __enable_if_t =3D typename std::enable_if::type [with bool= _Cond =3D false; _Tp =3D void]=E2=80=99: /usr/include/c++/12.2.1/type_traits:2238:11: required by substitution of =E2=80=98template using _Require =3D std::__enable_if_t >::value> [with _Cond =3D {std::integral_constant<= bool, false>}]=E2=80=99 /usr/include/c++/12.2.1/bits/alloc_traits.h:249:2: required by substituti= on of =E2=80=98template static constexpr std::_Require >::__construct_helper<_Tp, _Args>::type> std::allocator_traits >::_S_construct(b::alloc&, _Tp*, _Args&& ...) [with _Tp =3D a; _Args =3D= {}]=E2=80=99 /usr/include/c++/12.2.1/bits/alloc_traits.h:363:26: required by substitut= ion of =E2=80=98template static constexpr decltype (std::allocator_traits >::_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits< >::construct::__args)...)) std::allocator_traits >::construct(b::alloc&, _Tp*, _Args&& ...) [with _Tp =3D a; _Args =3D {}= ]=E2=80=99 /usr/include/c++/12.2.1/bits/vector.tcc:117:30: required from =E2=80=98co= nstexpr std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args =3D {}; _Tp =3D a; _Alloc =3D b::alloc; reference =3D a&]=E2=80=99 test.cpp:36:23: required from here /usr/include/c++/12.2.1/type_traits:2234:11: error: no type named =E2=80=98= type=E2=80=99 in =E2=80=98struct std::enable_if=E2=80=99 2234 | using __enable_if_t =3D typename enable_if<_Cond, _Tp>::type; | ^~~~~~~~~~~~~ /usr/include/c++/12.2.1/bits/alloc_traits.h: In substitution of =E2=80=98te= mplate static constexpr decltype (std::allocator_traits >::_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits< >::construct::__args)...)) std::allocator_traits >::construct(b::alloc&, _Tp*, _Args&& ...) [with _Tp =3D a; _Args =3D {}= ]=E2=80=99: /usr/include/c++/12.2.1/bits/vector.tcc:117:30: required from =E2=80=98co= nstexpr std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args =3D {}; _Tp =3D a; _Alloc =3D b::alloc; reference =3D a&]=E2=80=99 test.cpp:36:23: required from here /usr/include/c++/12.2.1/bits/alloc_traits.h:257:9: note: candidate: =E2=80=98template static constexpr std::_Require >::__construct_helper<_Tp, _Args>::type>, std::is_constructible<_Tp, _Args ...> > > std::allocator_traits< >::_S_construct(_Alloc&, _Tp*, _Args&& ...) [with _Args =3D _Tp; _Alloc =3D b::alloc]=E2=80=99 257 | _S_construct(_Alloc&, _Tp* __p, _Args&&... __args) | ^~~~~~~~~~~~ /usr/include/c++/12.2.1/bits/alloc_traits.h:257:9: note: template argument deduction/substitution failed: /usr/include/c++/12.2.1/bits/vector.tcc: In instantiation of =E2=80=98const= expr std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args =3D {}; _Tp =3D a; _Alloc =3D b::alloc; reference =3D a&]=E2=80=99: test.cpp:36:23: required from here /usr/include/c++/12.2.1/ext/alloc_traits.h:81:7: note: candidate: =E2=80=98template static constexpr std::__enable_if_t::pointer, _Ptr>, std::__not_ > >::value> __gnu_cxx::__alloc_traits<_Al= loc, >::construct(_Alloc&, _Ptr, _Args&& ...) [with _Ar= gs =3D _Ptr; _Alloc =3D b::alloc; =3D a]=E2=80=99 81 | construct(_Alloc& __a, _Ptr __p, _Args&&... __args) | ^~~~~~~~~ /usr/include/c++/12.2.1/ext/alloc_traits.h:81:7: note: template argument deduction/substitution failed: Here's a compiler explorer link for convenience: https://godbolt.org/z/qK1nxhbnW The code compiles if I add a dummy constructor method to the custom allocat= or, that internally just calls std::construct_at (https://godbolt.org/z/bM7rzoW= aK), but I think this shouldn't be necessary; the construct method is optional, = and std::allocator_traits>::construct should work as intended in both cases. I suppose this is caused by some sort of check of the "constructabil= ity" of a that fails because of the private destructor, but as far as I know allocator_traits::construct in c++20 should just forward to std::construct_= at without doing additional checks, which makes this behavior wrong. I don't know if it's relevant, but msvc compiles this without problems (https://godbolt.org/z/oEb6Ej4sr).=