From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7D6903858CD1; Thu, 21 Mar 2024 10:25:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D6903858CD1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1711016731; bh=ZpfVFw9h9XXR6Y94gDUcJ/NolOQw+pwXcHXUx4EEFUU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=E+MutOg9v0Q1z3GQAqieZ2UUUi/1HI9MnYkmMB6kTHVzho7fDXIrnrnQ6sOAaOZvX g/hmB4hPJHQ3X8kTwiawWL3rlWqhShRZH0fg5jukH2o2Ous/S6WsAmTB1D7MVsAykI iYcg8SplIoFYMLtDBcLC08b9vxt28nv8M8HFqMto= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/114410] compiler issue in reference_binding when using rvalue reference to member of const object Date: Thu, 21 Mar 2024 10:25:30 +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: 13.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: DUPLICATE 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=3D114410 --- Comment #5 from Jonathan Wakely --- No, because a (T) style cast can do almost anything. In this case it's equivalent to const_cast(static_cast(a->m_i)) which is valid code. -Wold-style-cast will warn about using any form of (T) cast, which can encourage you to be more careful and precise about what you're trying to do. If you had written it like this: std::cout << static_cast(a->m_i) << std::endl; Then it wouldn't even compile. tl;dr don't use C-style casts if you want the compiler to tell you when you= 're doing something wrong.=