From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8C810384C003; Sun, 7 Feb 2021 22:23:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C810384C003 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/98989] New: missing -Wfree-nonheap-object freeing std::strings over 15 bytes long Date: Sun, 07 Feb 2021 22:23:35 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.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: Sun, 07 Feb 2021 22:23:35 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98989 Bug ID: 98989 Summary: missing -Wfree-nonheap-object freeing std::strings over 15 bytes long Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- Given the test case below, -Wfree-nonheap-object detects the invalid attemp= t to free the std::string buffer provided the string constant it's initialized w= ith is no more than 15 characters long (plus the terminating nul). But the opt= ion fails to diagnose the invalid call once the string length is 16 or more. #include void f () { std::string str (STR); char *p =3D &str[0]; free (p); } $ g++ -DSTR=3D'"abcdefghijklmno"' -O2 -S -Wall t.C t.C: In function =E2=80=98void f()=E2=80=99: t.C:7:8: warning: =E2=80=98void free(void*)=E2=80=99 called on unallocated = object =E2=80=98str=E2=80=99 [-Wfree-nonheap-object] 7 | free (p); | ~~~~~^~~ t.C:5:15: note: declared here 5 | std::string str (STR); | ^~~=