From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2AD973857C7E; Fri, 27 Aug 2021 11:28:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2AD973857C7E From: "loximann at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug sanitizer/102095] New: Returned reference to temporary not caught by -fsanitize=undefined Date: Fri, 27 Aug 2021 11:28:18 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: sanitizer X-Bugzilla-Version: 11.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: loximann at gmail 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 cc 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, 27 Aug 2021 11:28:19 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102095 Bug ID: 102095 Summary: Returned reference to temporary not caught by -fsanitize=3Dundefined Product: gcc Version: 11.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: loximann at gmail dot com CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxi= n at gcc dot gnu.org Target Milestone: --- The following code results in undefined behaviour (I believe), but it is not caught by -fsanitize=3Dundefined: #include #include #include template std::function constant(const T& c) { return [c]() noexcept -> const T&{ return c; }; } template std::function()> zip_good(const std::function& f) { return [f]() { return std::tuple{f()}; }; } template std::function()> zip_bad(const std::function& f) { return [f]() { return std::tuple{f()}; }; // <- UNDEFINED if T is const r= ef } int main() { std::cout << std::get<0>(zip_good(constant(1.0))()) << std::endl; std::cout << std::get<0>(zip_bad(constant(1.0))()) << std::endl; }=