From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 963D3385B53C; Wed, 30 Nov 2022 14:44:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 963D3385B53C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669819496; bh=go57TYAH65NAEksnnnMFANGgDuZKdF7qQEyndc/BAfQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=eBxxqMHNf44cuVEtlOxmShWLILlcQ+14ZmQixgJofZUkDgp0nY40J7ECh9L/hQfeX BTKzscarLaMUa1QGpaoX1Hgh6s82LB9Cwzw05b1yMmS0NVMMzc0LT2+c9ppdP1nOAd ysv24jPQ/zPCKJ/AmUjFEt20HXcm7u9lwOxpCVhY= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106434] [12/13 Regression] Spurious -Wnull-dereference when using std::unique_copy() since r12-5187-g1ae8edf5f73ca5c3 Date: Wed, 30 Nov 2022 14:44:55 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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=3D106434 --- Comment #10 from Jonathan Wakely --- Slightly simpler, with correct assertion now: --- a/libstdc++-v3/include/bits/vector.tcc +++ b/libstdc++-v3/include/bits/vector.tcc @@ -139,6 +139,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { const size_type __n =3D __position - begin(); if (this->_M_impl._M_finish !=3D this->_M_impl._M_end_of_storage) + { + __glibcxx_assert(__position !=3D const_iterator()); + if (__position =3D=3D const_iterator()) + __builtin_unreachable(); // PR 106434 + if (__position =3D=3D end()) { _GLIBCXX_ASAN_ANNOTATE_GROW(1); @@ -159,6 +164,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_insert_aux(__position, __x); #endif } + } else #if __cplusplus >=3D 201103L _M_realloc_insert(begin() + (__position - cbegin()), __x); The __builtin_unreachable would be unnecessary if __glibcxx_assert expanded= to that when assertions are disabled (so the macro expands to either an assert= ion, or a hint that the condition is always true). I think I tried that and it caused problems though.=