From patchwork Fri Dec 31 09:30:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 49433 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5AF053858020 for ; Fri, 31 Dec 2021 09:30:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5AF053858020 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1640943049; bh=plQ8uhQ6J5Hw8UxGJiA2t2LhG2o837LWslG0zPcMpe8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=OhA9yfxw27aa5nCHKnh4IPVD9u/XZrUPDWH7JmxaLOhr61Yl6uSw9OS9a+lHQORhK VgdO086o1Gkb7LaiUcooafO40kAhuM0cMcjZXQj5JZuj2uN5Uu+eWp/27B7vAUF1QP 2eV41tgg/ZKABWBwEV2seetiB7YLETacfdnlpQGM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id F29AC3858D39 for ; Fri, 31 Dec 2021 09:30:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F29AC3858D39 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-439-Y0A_Z1FGMlOmFpU0FrbRMw-1; Fri, 31 Dec 2021 04:30:18 -0500 X-MC-Unique: Y0A_Z1FGMlOmFpU0FrbRMw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EBBF5185302A for ; Fri, 31 Dec 2021 09:30:17 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.2.16.169]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8739984634; Fri, 31 Dec 2021 09:30:09 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 1BV9U7qJ1283974 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 31 Dec 2021 10:30:07 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 1BV9U6wo1283973; Fri, 31 Dec 2021 10:30:06 +0100 Date: Fri, 31 Dec 2021 10:30:06 +0100 To: Jason Merrill Subject: [PATCH] c++: Silence -Wuseless-cast warnings during move [PR103480] Message-ID: <20211231093006.GE2646553@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! This is maybe just a shot in the dark, but IMHO we shouldn't be diagnosing -Wuseless-cast on casts the compiler adds on its own when calling its move function. We don't seem to warn when user calls std::move either. We call move on elinit (*NON_LVALUE_EXPR <(struct C[2] &&) &D.2497->b>)[0] so it is already an xvalue_p and try to static_cast it to struct C &&. But we don't warn e.g. on std::move (std::move (whatever)). Bootstrapped/regtested on x86_64-linux and i686-linux. 2021-12-31 Jakub Jelinek PR c++/103480 * tree.c (move): Add warn_useless_cast warning sentinel. * g++.dg/warn/Wuseless-cast2.C: New test. Jakub --- gcc/cp/tree.c.jj 2021-12-30 15:12:42.739157171 +0100 +++ gcc/cp/tree.c 2021-12-30 18:39:08.050679041 +0100 @@ -1288,6 +1288,7 @@ move (tree expr) tree type = TREE_TYPE (expr); gcc_assert (!TYPE_REF_P (type)); type = cp_build_reference_type (type, /*rval*/true); + warning_sentinel w (warn_useless_cast); return build_static_cast (input_location, type, expr, tf_warning_or_error); } --- gcc/testsuite/g++.dg/warn/Wuseless-cast2.C.jj 2021-12-30 18:46:17.437651681 +0100 +++ gcc/testsuite/g++.dg/warn/Wuseless-cast2.C 2021-12-30 18:45:41.044162541 +0100 @@ -0,0 +1,24 @@ +// PR c++/103480 +// { dg-do compile { target c++14 } } +// { dg-options "-Wuseless-cast" } + +template +struct A { typedef T t[N]; }; +template +struct B { typename A::t b; }; +struct C { + constexpr C (C &&) {} + template + static auto bar () + { + B r; + return r; // { dg-bogus "useless cast to type" } + } + C () = default; +}; + +void +foo () +{ + C::bar<2> (); +}