From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E3B30385DC15; Fri, 20 Aug 2021 14:35:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E3B30385DC15 From: "peciva at fit dot vut.cz" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/101998] New: false positive: taking address of rvalue Date: Fri, 20 Aug 2021 14:35:56 +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: 11.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: peciva at fit dot vut.cz 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: Fri, 20 Aug 2021 14:35:57 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101998 Bug ID: 101998 Summary: false positive: taking address of rvalue Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: peciva at fit dot vut.cz Target Milestone: --- Following code refuses to compile (on g++ 7.5 and 11.2): struct Nested { int payload; }; struct Main { const Nested* nested; int payload; Main(const Nested* n) : nested(n) {} }; void f(const Main& s) { } int main() { f(Main(&(const Nested&)Nested())); // <- workaround f(Main(&Nested())); // <- fails here return 0;=20 } Error message: "error: taking address of rvalue" I am not c++ expert, but the code seems perfectly meaningful to me. Structu= re Main and Nested are both constructed before the call to f and both of them = are destructed after the execution of f. No dangling pointer to destructed temporary. Both structures (Main, Nested) are temporaries and I do not see a real reason why the compilation should fail. Maybe, if Main and Nested instances are both temporaries, the error should not be emitted and compila= tion shall proceed (?). But I am not expert. Such constructions of temporary nested structures and passing pointers to m= ain structure constructor are often used when programming with c++ Vulkan API, = for instance.=