From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A8875385841C; Thu, 2 Nov 2023 15:02:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8875385841C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1698937327; bh=dYI4bEavuLyJdyoWW5KxjhSi5XxJW0Kr1Mt1a08LVNU=; h=From:To:Subject:Date:From; b=ENKZ6Yv1r4whzJVPQrHdhZhqgAznJPQ9hjznKBrdC1NyKS1kmD0SqOFXR6AkG+qL6 BWJH1rl/ojkI5cNPtKgHrVJpYUhMWRClwYa+IFFRWOKn8bhgZQAtRK7Rwe5l39UD2Q r3ohQOGXZ2QagCMJ7UNxqakqtvl4tJpLDD+JV5B4= From: "mohamed.selim at dxc dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/112350] New: gcc is not triggering a dangling reference indicating stack use after return Date: Thu, 02 Nov 2023 15:02:07 +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: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mohamed.selim at dxc 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 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=3D112350 Bug ID: 112350 Summary: gcc is not triggering a dangling reference indicating stack use after return Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mohamed.selim at dxc dot com Target Milestone: --- Scenario A: gcc is not triggering a dangling reference indicating stack use after retur= n, the address-sanitizer does trigger though. "=3D=3D1=3D=3DERROR: AddressSanitizer: stack-use-after-return on" Scenario B: gcc triggers a warning "-Wreturn-local-addr" The sanitizers intervenes in both scenarios as expected, while gcc warnings= in not triggered in scenario A. Looks like the reference_wrapper has something= to do with it. compiler options used: -std=3Dc++14 -Wframe-address -Wreturn-local-addr -Wall -Wextra -Wpedantic -fsanitize=3Daddress #include #include // scenario A const int& foo() { int x =3D 234; std::reference_wrapper s{x}; return s.get(); } // scenario B const int& foo() { int s =3D 234;=20=20=20 return s; } int main() { const auto& f_res =3D foo(); std::cout << "result: " << f_res << "\n"; return 0; }=