From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17756 invoked by alias); 28 Apr 2017 09:11:25 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 17702 invoked by uid 89); 28 Apr 2017 09:11:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2150, HX-Received:Fri, they're, theyre X-HELO: mail-wr0-f175.google.com Received: from mail-wr0-f175.google.com (HELO mail-wr0-f175.google.com) (209.85.128.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 28 Apr 2017 09:11:16 +0000 Received: by mail-wr0-f175.google.com with SMTP id l50so30088352wrc.3 for ; Fri, 28 Apr 2017 02:11:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=JlK+ijRFX8cVGVl+A1eMY3LlxLT0M1YEHMxaZkfaU90=; b=RJcKjeK5fK1STl3a6z8LCuzsD7LwgZPYsWrZfnegjt03yavoy+DmQBSHmsy7N8Ql1Z qYrOdIcYe2pE+PGzvSzDAppKYQc2QSCFyR8tMHRcA/cjHsT18lLmfrJFsmrJHTMc/zSi 9zzh72FO0k6J7s2/5m0aPKZDGeJZsHVNICL5qyz7RJC7jvHytoN00qApRyWtO51NeyUV 1dMDQ0IOPDtA1StRlSorfEUl0bIwRPRbVYCtohGC6hMyEuKSixcZxupbq/us/8sHpWkM 31EAgKhKo2AZnORQm9DkPS80y7GNh5rPRSdFgFkNfOgA41bySxCAEqzK/tzqo6QFMLpq VdeQ== X-Gm-Message-State: AN3rC/6CAlPLmlMT+si2+KtB1eVixzS1gPwM0EvJ4juwClWNFv49Lam2 zA8TsfPLuGiM/g== X-Received: by 10.223.162.147 with SMTP id s19mr6328679wra.142.1493370676919; Fri, 28 Apr 2017 02:11:16 -0700 (PDT) Received: from E107787-LIN ([194.214.185.158]) by smtp.gmail.com with ESMTPSA id h8sm1409784wmf.28.2017.04.28.02.11.15 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 28 Apr 2017 02:11:16 -0700 (PDT) From: Yao Qi To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 5/6] Use copy ctor in regcache_dup References: <1493152106-3246-1-git-send-email-yao.qi@linaro.org> <1493152106-3246-6-git-send-email-yao.qi@linaro.org> Date: Fri, 28 Apr 2017 09:11:00 -0000 In-Reply-To: (Pedro Alves's message of "Thu, 27 Apr 2017 18:37:24 +0100") Message-ID: <86shksc2xb.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2017-04/txt/msg00766.txt.bz2 Pedro Alves writes: > This one doesn't look right to me. This isn't a copy in the > normal C++ object copy sense. The new object isn't semantically the > same as the source. One can't use the new object the same way as the > source regcache, they're not interchangeable. This is bound to generate > confusion and problems. I thought about this. The reason I still do this is that I can't think of a case that we need to copy a read-write regcache to another read-write regcache. So far, we only use copy(or transform) a read-write regcache to a read-only regcache. However, I agree with you, it is not a normal "copy ctor". > > Considering patch #6, it'd make more sense to me to > make that a separate constructor with tag dispatching, like: > > struct regcache > { > struct readonly_t {}; > static constexpr readonly_t readonly {}; > > regcache (readonly_t, const regcache &src); // old regcache_dup > }; > > Then used like: > > regcache ro_copy (regcache::readonly, src); > > or if you want, you could make that tag-based ctor private and > add a factory function: > > struct regcache > { > private: > struct readonly_t {}; > regcache(readonly_t, const regcache &src); > > regcache(regcache &&src) { // implement this } // move ctor > > public: > static regcache make_readonly_copy (const regcache &src) > { > return regcache (readonly_t{}, src); > } > }; > > Used like=20 > > regcache ro_copy =3D regcache::make_readonly_copy (src); I have a different design on this, that is, put readonly regcache and readwrite regcache to two classes. readwrite regcache inherits readonly regcache, and readonly regcache has a constructor whose argument is a readwrite regcache. class readonly_regcache { public: explicit readonly_regcache (const regcache &); } class regcache : public readonly_regcache { } What do you think? > > In any case, I think we should make sure to disable > the regular copy methods since the type doesn't really > support normal copy: > > regcache(const regcache &) =3D delete; > void operator=3D (const regcache &) =3D delete; I agree. I'll add it. --=20 Yao (=E9=BD=90=E5=B0=A7)