From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 E7A133858C2F for ; Thu, 25 Aug 2022 13:25:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E7A133858C2F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661433948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EVW/DMz4j5NT6a+KV75HTp2pLi5sfZTbXLRxT5EPe5A=; b=AIh0dP5i/HnSI6VQo3TRdkayu4awqAb8OAOKNH+QDAw3pgnRi23Vivqowbp6KNlHVEHUbY hGNqy2N+vt2b9mEHhHUqnWuYOkFl9QvheERNrS+s83uhRwWu73E+SAIC7ZGsuPFmXvcZTM xGS1YJN0FyUySs4deEDbQ+V8GZby3HI= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-247-5xp6Zue9M-OuofzFBkKjJA-1; Thu, 25 Aug 2022 09:25:46 -0400 X-MC-Unique: 5xp6Zue9M-OuofzFBkKjJA-1 Received: by mail-qt1-f200.google.com with SMTP id fv24-20020a05622a4a1800b003445e593889so15005041qtb.2 for ; Thu, 25 Aug 2022 06:25:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=EVW/DMz4j5NT6a+KV75HTp2pLi5sfZTbXLRxT5EPe5A=; b=HqmOHsS1pdPy9SH73PQnnQLbG8A3j5rBJG6trs/iZk29Fvr6emgNACl7uRV3ZPpBaO sXRVhZq51fjo43dcRU96FE/7k1TAaCx1HqXZmQaVmFOOAz9Xy/UbApfbhnaME5Vt3TRz zcXYrEk/SikisWcRCyO3YPsRo8yWZ72UDx0+cheWUgLxKHGl3Pz5Dk28qGpXE7N1Vbkf X0ANkjAHMhW8z2XoYnM78hlJo2auWiSchG1vuxZZ3nGgSL2S3jCvElwvmn2gtcMLs0Mg x5KhVQl1mFNrMFLvt59WwW9uQJlMtA4hQWrh+lDSfMUTZNIyD4MbL/4yO3kkWt3iDEyN Xmbg== X-Gm-Message-State: ACgBeo0l0YfzH0lcq445FX7mnTstyAMXIVWk6ix55fOfnIukL/3nVm6v HBNyo+M8FrzfuVcd4PVJkV4DUhOKlQaQopECY7IJbkiXTY40tBiJoGIWr4rdB2hWQKj8Pmgf6yR MMMjGD4C3mp3ky/DruA== X-Received: by 2002:a05:622a:1112:b0:344:8e18:6d97 with SMTP id e18-20020a05622a111200b003448e186d97mr3474256qty.583.1661433945607; Thu, 25 Aug 2022 06:25:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR4LMRBFvWP2os2t2EJYrK/IFG5+aBAVB+Ey2yCODWfeTH0kKfUMdYjpLmXsbb8XVwcPbGCEGQ== X-Received: by 2002:a05:622a:1112:b0:344:8e18:6d97 with SMTP id e18-20020a05622a111200b003448e186d97mr3474238qty.583.1661433945287; Thu, 25 Aug 2022 06:25:45 -0700 (PDT) Received: from [192.168.1.101] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id g18-20020a05620a40d200b006bb9e4b96e6sm18599471qko.24.2022.08.25.06.25.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Aug 2022 06:25:44 -0700 (PDT) Message-ID: Date: Thu, 25 Aug 2022 09:25:43 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [PATCH v4] c++: Implement -Wself-move warning [PR81159] To: Marek Polacek Cc: GCC Patches References: <20220809163719.381319-1-polacek@redhat.com> <1ca5b35f-0fa6-be28-290f-701c5ac43807@redhat.com> <3e9dea44-1e0e-e329-575a-aa621d19deeb@redhat.com> <9e980813-7ab7-25dc-7f74-56faaafafb84@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 8/24/22 17:30, Marek Polacek wrote: > On Tue, Aug 23, 2022 at 05:27:00PM -0400, Jason Merrill wrote: >> On 8/23/22 09:39, Marek Polacek wrote: >>> + tree arg = CALL_EXPR_ARG (fn, 0); >>> + extract_op (arg); >>> + if (TREE_CODE (arg) == ADDR_EXPR) >>> + arg = TREE_OPERAND (arg, 0); >>> + tree type = TREE_TYPE (lhs); >>> + lhs = maybe_undo_parenthesized_ref (lhs); >>> + STRIP_ANY_LOCATION_WRAPPER (lhs); >>> + const bool print_var_p = (DECL_P (lhs) >>> + || REFERENCE_REF_P (lhs) >>> + || TREE_CODE (lhs) == COMPONENT_REF); >> >> Why include REFERENCE_REF_P and COMPONENT_REF? Reference refs should be >> stripped before this test, member refs aren't variables. > > I'm checking REFERENCE_REF_P and COMPONENT_REF to say "moving a variable" > in #1 and #3. The REFERENCE_REF_P check means that we also say "variable" > for #2. Sure, "A variable is introduced by the declaration of a reference > other than a non-static data member", but I'm not sure if users care about > that here? > > If I strip REFERENCE_REFs before the check then the result will be the > same. That's what I was suggesting, yes: Strip the REFERENCE_REF so DECL_P can see the decl. I don't see where COMPONENT_REF comes in? > Or I could keep only the DECL_P check, but then we'll say "moving > an expression" for #1 and #2, which seems strange. > > struct S { > int x; > int &r; > void foo () { > x = std::move (x); // #1 > r = std::move (r); // #2 > }; > }; > > void > foo (int &r) > { > r = std::move (r); // #3 > } > > Marek >