From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 26F0E3858CDA; Wed, 19 Apr 2023 09:45:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26F0E3858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681897541; bh=vi5ywn7TAZzHbavSymuU+cbR4PFi2p1RqqLSuI5DPwM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fi+2QPBNTJ8MN14SYTavNW3G5ClSQh2mzK5WtJ9YLFpq3dNnWsPVUl7crh8uudRH8 bBqvP/OH4pPARUJsoVv+bzQFTeftFF565iXs8o7KvZWG7NCrDsECpN/lmiwau4TRPz DORj0EpnFGQ/827/1PoyEgWo9apkC9AuHhd159FU= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109548] Detect c_str() dangling problems Date: Wed, 19 Apr 2023 09:45:39 +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: 13.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW 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: cc 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=3D109548 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dmalcolm at gcc dot gnu.or= g, | |rguenth at gcc dot gnu.org --- Comment #2 from Richard Biener --- David possibly has inputs on how this should be done so the analyzer can do this kind of diagnostic. Generally I'd say we want sth like T * __attribute__ ((return_lifetime(1))) foo (U *p, ...); where we specify the lifetime of the returned referenced object to be the same as a referenced object in the argument list? So yes, the [[gnu::lifetime(this)]] attribution would maybe do that but can the attribute refer to another explicitely named argument as well? Btw, is there an API to std::move the (possibly) allocated string out of the std::string and make it available as C string pointer?=