From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 189103858D38; Tue, 11 Apr 2023 08:36:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 189103858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681202190; bh=eATHPU3vPejmRAvmZ32s+szaoC7bBPzAbjEy6/HGrI0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=IRdX+YY42vS8j7wjdecv+jyExSG5Qt9gLgEty1oJR4m09s92wWpQEx7tv4BvaGykQ UCs04oKRKXEgqB8xQZVaPZr/tZWp9O/PnjN3Onkebc4x51RluR9VK5B+9DtCKpqYAZ 6qxo6D/LkPGtzm9MA0yTzs5DHn6OzOCfR81U8O54= From: "xry111 at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109470] unexpected const & behavior Date: Tue, 11 Apr 2023 08:36:29 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: xry111 at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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: Message-ID: In-Reply-To: References: 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=3D109470 --- Comment #2 from Xi Ruoyao --- With "-Wall -O1" this is diagnosed properly, but with a spurious maybe-uninitialized warning: In file included from /usr/include/c++/12.2.0/cassert:44, from t.c:2: t.c: In function 'int main()': t.c:17:11: warning: dangling pointer 'dst' to an unnamed temporary may be u= sed [-Wdangling-pointer=3D] 17 | assert(dst <=3D MAX); | ^~~ t.c:16:24: note: unnamed temporary defined here 16 | const int& dst =3D Min(MAX, (int)lenght); | ~~~^~~~~~~~~~~~~~~~~~ t.c:16:24: warning: '' may be used uninitialized [-Wmaybe-uninitialized] With "-Wall -O2" only the spurious maybe-uninitialized warning is emitted, which is not very helpful. With "-Wall -O0" no warning at all (diagnosing this issue at least needs so= me IPA).=