From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C26393858C2D; Wed, 19 Oct 2022 19:30:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C26393858C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666207834; bh=H3IAapunefV82Zpwmq3v4pPpm8hCtP/mbD7uH6VAjXA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MAAccEp4mdxCV/VZDrLWyvNnoFiLvaeQyV6oY+NwEmnJISpNhBDh4OKlDR1rsoYYl C1erJ9EV2HONSgC/BuBYo2AdPgb6QtBRM7JJGhl88xE6KzYkyQ5c58wgO9W1zzl5GP cpC1YpQXS177dXffNIq1w9vsdcqx/CL1mYIihhsU= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/85043] -Wuseless-cast false positive for temporary objects; add separate -Wcast-to-the-same-type to cover that case instead Date: Wed, 19 Oct 2022 19:30:33 +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: 7.3.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: mpolacek 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=3D85043 --- Comment #15 from CVS Commits --- The trunk branch has been updated by Marek Polacek : https://gcc.gnu.org/g:b3c98d6a59a6dcd5b0b52bd5676b586ef4fe785f commit r13-3388-gb3c98d6a59a6dcd5b0b52bd5676b586ef4fe785f Author: Marek Polacek Date: Tue Oct 18 12:20:14 2022 -0400 c++: Mitigate -Wuseless-cast with classes [PR85043] -Wuseless-cast (not part of -Wall/-Wextra) warns here: struct S { }; void g (S&&); void f (S&& arg) { g (S(arg)); // warning: useless cast to type 'struct S' } which is wrong: the code will not compile without the cast because "arg" is an lvalue which cannot bind to S&&. This patch disables the warning when an object that isn't a prvalue is cast to a non-reference type. Therefore we still warn about the useless cast in "X(X{})". PR c++/85043 gcc/cp/ChangeLog: * typeck.cc (maybe_warn_about_useless_cast): Don't warn when a glvalue is cast to a non-reference type. gcc/ChangeLog: * doc/invoke.texi: Update documentation of -Wuseless-cast. gcc/testsuite/ChangeLog: * g++.dg/warn/Wuseless-cast.C: Remove dg-warning. * g++.dg/warn/Wuseless-cast3.C: New test.=