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.133.124]) by sourceware.org (Postfix) with ESMTPS id 21F69385C335 for ; Wed, 24 Aug 2022 21:31:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 21F69385C335 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=1661376663; 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: in-reply-to:in-reply-to:references:references; bh=7oZhcs9TgftYfY4w6e+kIwZIQ57i7fDDXHWld0uiSGY=; b=LXT71RwIijGPZINJG7MBi3229gXGNCXbPKyKjdf6ixyMKDS2VY5CjGmYaCQT4lTBukxlxb ipd+mDvdVT/eOqPin8p2w4h1p6Gctj14jXYVh76QTfEJn716buwsXyjeQQqzF4MdCzgdxT BV7DF6dJQWzV5iE5O+QI1TnQEUabsAA= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-590-i7awf9NNPnq6xDDq7xn2IA-1; Wed, 24 Aug 2022 17:31:02 -0400 X-MC-Unique: i7awf9NNPnq6xDDq7xn2IA-1 Received: by mail-qt1-f197.google.com with SMTP id v13-20020a05622a188d00b00343794bd1daso13988082qtc.23 for ; Wed, 24 Aug 2022 14:31:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=7oZhcs9TgftYfY4w6e+kIwZIQ57i7fDDXHWld0uiSGY=; b=f98s98GQwifTP5OrYKsAgdy+u3jdfz3qGbEJjNxhxTh6y+nHRgCrm+3v+ppkcqn67q bdlRUgYEVDkWsYrAknEU0ZgZ//K3z610NLSjbylTdaE1BypiWH7Dxn1SuC8+zDWuhhQy Cl5xtWEL3cSHmOEq9KwypDbgii7rX+/1e9l04zzDo5+yZ2dJ6dkWCk5SPWpjWMymQMgL 0hqx18ULk0Ht/hUIjyY7K65oyBPvPiGTY6IMU0eeRDwXzFinXkfiehDWjB1lzi3nauM7 m3hy0WeCjHq7GdSqEhiFEiKHju0bc0YKb3kbRC0tSGU7aqkMwCy62QJx7eGM035Yl1Uj /Yxg== X-Gm-Message-State: ACgBeo27aGLtkyEGqDh97Zud3z36o3HhjDYLpdxnKBlCOjJMS0SFfb62 vgieFNB2Kn+PigKcD/qDhAtlY8xngQamveMH/gYiooOebB7i4mbi1PaI41SC0PQKKv9vHE72e5s cem7UfSilVGi1rekoFQ== X-Received: by 2002:a05:620a:2956:b0:6bc:5144:1260 with SMTP id n22-20020a05620a295600b006bc51441260mr942071qkp.181.1661376662327; Wed, 24 Aug 2022 14:31:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR7lDH4JI5e9XSsvSPB4p7y7uoMlER5VNtFmec/GX9y7BxHBtygfpaG7vZVl2JyVY64sbfvIVA== X-Received: by 2002:a05:620a:2956:b0:6bc:5144:1260 with SMTP id n22-20020a05620a295600b006bc51441260mr942050qkp.181.1661376662031; Wed, 24 Aug 2022 14:31:02 -0700 (PDT) Received: from redhat.com ([2601:184:4780:4310::e531]) by smtp.gmail.com with ESMTPSA id t24-20020a37ea18000000b006b9526cfe6bsm16214835qkj.80.2022.08.24.14.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 14:31:01 -0700 (PDT) Date: Wed, 24 Aug 2022 17:30:59 -0400 From: Marek Polacek To: Jason Merrill Cc: GCC Patches Subject: Re: [PATCH v4] c++: Implement -Wself-move warning [PR81159] Message-ID: 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> MIME-Version: 1.0 In-Reply-To: <9e980813-7ab7-25dc-7f74-56faaafafb84@redhat.com> User-Agent: Mutt/2.2.6 (2022-06-05) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,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 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. 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