From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 62F6B384F02D; Wed, 11 May 2022 19:06:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 62F6B384F02D From: "cuzdav at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105571] New: Spurious "set but not used" on static constexpr local, used in lambda Date: Wed, 11 May 2022 19:06:34 +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.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cuzdav 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 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: Wed, 11 May 2022 19:06:34 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105571 Bug ID: 105571 Summary: Spurious "set but not used" on static constexpr local, used in lambda Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: cuzdav at gmail dot com Target Milestone: --- With -Wall, in every c++ language level on virtually every version of g++ as far back as 4.9, g++ warns ("variable 'THIS_IS_USED' set but not used") on = the following complete code: template void for_each(IterT b, IterT e, FuncT f) { while (b !=3D e) { f(*b++); } } volatile int sink;=20 void xxx(int x) { sink =3D x; } void foo() { static constexpr auto THIS_IS_USED =3D 1;=20=20 int arr[10]{1,2,3,4,5,6,7,8,9,10}; for_each(arr, arr+10, [](auto v) { xxx(THIS_IS_USED + v); }); } : In function 'void foo()': :15:27: warning: variable 'THIS_IS_USED' set but not used [-Wunused-but-set-variable] 15 | static constexpr auto THIS_IS_USED =3D 1; | ^~~~~~~~~~~~ Compiler returned: 0 https://godbolt.org/z/b1s5Yqb3r This appears to be related to the "auto" parameter in the lambda. Changing= it to 'int' makes the problem go away.=