From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 73FF63858418; Sat, 5 Nov 2022 05:16:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 73FF63858418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667625385; bh=jrE2NX6PS5oes+lRyQwZvUtxS3N2M+g7CE5AeShJUZw=; h=From:To:Subject:Date:From; b=BknU+plIH7xJbmmjlX2Hdi/GjHfXXriQzPWMDsUDctT+HN8L1IqY4bc8tyUyTxOQE wG5SrQcx8z7zD+Y7BfPQsrZH/Gj6YY9ybcsmD+LUCVN0oaT/BCqWvHwj2U/WP8Qfhc d9JZ0CCWSQhxnwaj0/CiVCswRIoaNxNRlh9Psbz4= From: "nightstrike at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107531] New: List of references calls destructors, add warning? Date: Sat, 05 Nov 2022 05:16:24 +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: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: nightstrike 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 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=3D107531 Bug ID: 107531 Summary: List of references calls destructors, add warning? Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: nightstrike at gmail dot com Target Milestone: --- The following code results in a destructor being calling twice: #include struct S { S() { __builtin_printf("ctor\n"); } ~S() { __builtin_printf("dtor\n"); } }; template void f(Args const & ... args) { for (auto const & s: { args... }) ; } int main() { S s; f(s); } $ ./a.out ctor dtor dtor Changing line 9 to use pointers fixes it: for (auto const * s: { &args... }) $ ./a.out ctor dtor I think that if my code is exploiting some kind of bad behavior (and it lik= ely is), a warning at -Wall would be a nice addition (currently, there is none)= .=20 If what I'm doing is allowed, I don't think calling a destructor twice is t= he best idea :) :). I'd be betting money on the first thing, though. Maybe adding something from -fsanitize=3Dundefined would be an option?=