From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8D50F383B7A4; Mon, 25 Jul 2022 14:46:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D50F383B7A4 From: "vz-gcc at zeitlins dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106434] New: Spurious -Wnull-dereference when using std::unique_copy() Date: Mon, 25 Jul 2022 14:46:32 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vz-gcc at zeitlins 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jul 2022 14:46:32 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106434 Bug ID: 106434 Summary: Spurious -Wnull-dereference when using std::unique_copy() Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: vz-gcc at zeitlins dot org Target Milestone: --- The following simple example shows the problem with g++ 12, which didn't ex= ist with the previous versions: % g++ -v Using built-in specs. COLLECT_GCC=3D/usr/bin/g++ COLLECT_LTO_WRAPPER=3D/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper OFFLOAD_TARGET_NAMES=3Dnvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=3D1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion=3D'Debian 12.1.0-7' --with-bugurl=3Dfile:///usr/share/doc/gcc-12/README.Bugs --enable-languages=3Dc,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=3D/usr --with-gcc-major-version-only --program-suffix=3D-12 --program-prefix=3Dx86_64-linux-gnu- --enable-shared --enable-linker-build-= id --libexecdir=3D/usr/lib --without-included-gettext --enable-threads=3Dposix --libdir=3D/usr/lib --enable-nls --enable-clocale=3Dgnu --enable-libstdcxx-= debug --enable-libstdcxx-time=3Dyes --with-default-libstdcxx-abi=3Dnew --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=3Drelea= se --with-target-system-zlib=3Dauto --enable-objc-gc=3Dauto --enable-multiarch --disable-werror --enable-cet --with-arch-32=3Di686 --with-abi=3Dm64 --with-multilib-list=3Dm32,m64,mx32 --enable-multilib --with-tune=3Dgeneric --enable-offload-targets=3Dnvptx-none=3D/build/gcc-12-aYRw0H/gcc-12-12.1.0/= debian/tmp-nvptx/usr,amdgcn-amdhsa=3D/build/gcc-12-aYRw0H/gcc-12-12.1.0/deb= ian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=3Drelease --build=3Dx86_64-linux-gnu --host=3Dx86_64-linux-gnu --target=3Dx86_64-linu= x-gnu Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.1.0 (Debian 12.1.0-7) % cat unique_copy.cpp #include #include #include #include std::vector const& parms(); int main() { std::vector all; for(auto const& i : parms()) { all.push_back(i); } std::vector unique; std::insert_iterator iin(unique, unique.begin()); // EXCHANGE THESE LIN= ES std::sort(all.begin(), all.end()); // TO SUPPRESS THE WARNING std::unique_copy(all.begin(), all.end(), iin); } % g++ -std=3Dc++20 -c -O2 -Wnull-dereference unique_copy.cpp In file included from /usr/include/c++/12/string:53, from /usr/include/c++/12/bits/locale_classes.h:40, from /usr/include/c++/12/bits/ios_base.h:41, from /usr/include/c++/12/streambuf:41, from /usr/include/c++/12/bits/streambuf_iterator.h:35, from /usr/include/c++/12/iterator:66, from unique_copy.cpp:2: In constructor =E2=80=98constexpr std::__cxx11::basic_string<_CharT, _Trait= s, _Alloc>::_Alloc_hider::_Alloc_hider(std::__cxx11::basic_string<_CharT, _Tra= its, _Alloc>::pointer, _Alloc&&) [with _CharT =3D char; _Traits =3D std::char_traits; _Alloc =3D std::allocator]=E2=80=99, inlined from =E2=80=98constexpr std::__cxx11::basic_string<_CharT, _Tra= its, _Alloc>::basic_string(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT =3D char; _Traits =3D std::char_traits; _Alloc= =3D std::allocator =E2=80=99 at /usr/include/c++/12/bits/basic_string.h:5= 40:9, inlined from =E2=80=98constexpr decltype (::new(void*(0)) _Tp) std::construct_at(_Tp*, _Args&& ...) [with _Tp =3D __cxx11::basic_string; _Args =3D {const __cxx11::basic_string, allocator >&}]=E2=80=99 at /usr/include/c++/12/bits/stl_construct.h:97:14, inlined from =E2=80=98static constexpr void std::allocator_traits >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up =3D std::__cxx11::basic_string; _Args = =3D {const std::__cxx11::basic_string, std::allocator >&}; _Tp =3D std::__cxx11::basic_string]=E2=80=99 at /usr/include/c++/12/bits/alloc_traits.h:518:21, inlined from =E2=80=98constexpr std::vector<_Tp, _Alloc>::iterator std:= :vector<_Tp, _Alloc>::insert(const_iterator, const value_type&) [with _Tp =3D std::__cxx11::basic_string; _Alloc =3D std::allocator >]=E2=80=99 at /usr/include/c++/12/bits/vector.tcc:145:30, inlined from =E2=80=98constexpr std::insert_iterator<_Container>& std::insert_iterator<_Container>::operator=3D(const typename _Container::value_type&) [with _Container =3D std::vector >]=E2=80=99 at /usr/include/c++/12/bits/stl_iterator.h:964:26, inlined from =E2=80=98constexpr _OutputIterator std::__unique_copy(_ForwardIterator, _ForwardIterator, _OutputIterator, _BinaryPredicate, forward_iterator_tag, output_iterator_tag) [with _ForwardIterator =3D __gnu_cxx::__normal_iterator<__cxx11::basic_string*, vector<__cxx11::basic_string > >; _OutputIterator =3D insert_iterator > >; _BinaryPredicate =3D __gnu_cxx::__ops::_Iter_equal_to_iter]=E2=80=99 at /usr/include/c++/12/bits/stl_algo.h:1002:17, inlined from =E2=80=98constexpr _OIter std::unique_copy(_IIter, _IIter,= _OIter) [with _IIter =3D __gnu_cxx::__normal_iterator<__cxx11::basic_string*, vector<__cxx11::basic_string > >; _OIter =3D insert_iterator > >]=E2=80=99 at /usr/include/c++/12/bits/stl_algo.h:4474:32, inlined from =E2=80=98int main()=E2=80=99 at unique_copy.cpp:18:21: /usr/include/c++/12/bits/basic_string.h:204:43: warning: null pointer dereference [-Wnull-dereference] 204 | : allocator_type(std::move(__a)), _M_p(__dat) { } | ^~~~~~~~~~~ [...several more pages of similar output with more -Wnull-dereference occurrences snipped...] I could work around this bug by simply moving the call to std::sort() before insert_iterator ctor (i.e. just exchanging the marked lines avoids the warning), but it looks wrong to have to use such voodoo just to make my real code compile without warnings again.=