From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BA0E73858C53; Wed, 14 Jun 2023 01:34:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA0E73858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686706471; bh=CnmTDbC2LvgUIeZKKWa12m+wTMPiRzCgAOmjVH3L638=; h=From:To:Subject:Date:From; b=q2YW0JVYAxHO6xpPXmg5P9U6GTITWkT524gBPkfK7/4G1XVwTe6mHCQdOOTi8MsA5 zECjVtY+ddmC8AFO2gCagNYSXW7mHRQ8AzeeeSDWDBLDCMrQqjKBqixq5zFiTHpBe1 QZmtcsXBUdz5exHJaW6pTYxEVc2UBLGwceb6EHYo= From: "gimira8592 at aramask dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110244] New: False error of vector memory leak Date: Wed, 14 Jun 2023 01:34:30 +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.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gimira8592 at aramask dot com 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 attachments.created 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=3D110244 Bug ID: 110244 Summary: False error of vector memory leak Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: gimira8592 at aramask dot com Target Milestone: --- Created attachment 55320 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D55320&action=3Dedit the preprocessed file (*.i*) that triggers the bug, generated by adding -save-temps Version of GCC: (Ubuntu 12.2.0-17ubuntu1) 12.2.0 OS and Version: Ubuntu 23.04, Linux 6.2.0-20-generic GCC configuration: -fanalyzer std=3Dc++20 To trigger bug run this code int main() { std::vector vec(2); } and when you try to compile it, you should see this error leak of =E2=80=98vec.std::vector::.std::_Vector_base >::_M_impl.std::_Vector_base >::_Vector_impl::.std::_Vector_base >::_Vector_impl_data::_M_start=E2=80=99 [CWE-401] [-Werror=3Danalyzer-mallo= c-leak] Looks like a bug in GCC's static analyzer, because that code certainly does= not leak. Interestingly it only happens with C++20 It still happens with the latest GCC versions: https://godbolt.org/z/o6GbGc= MaP=20 Apparently its trigger by the addition of constexpr to the ctor/dtor in C++= 20 (and beyond).=20 Apparently this error does not seem to occur with std::string but it do occ= ur with data type like int, double, long and char and fails to compile. If you just create an uninitialized vector or default initialize with brace= , it will compile without any error but if you set it size or initialize with a value then it will give memory leak error. To show that this is related to constexpr on the ctor/dtor, you can #define _GLIBCXX20_CONSTEXPR before #including in the C++20 version. If you do that to effectively "define away" the constexpr in the C++20 vers= ion, the static analyzer wont fail. Of course that is very much UB and pretty dangerous (as you are actively meddling with the internals of the library a= nd the compilers assumptions), but it shows the point.=