220 7597 <CAOfiQqkxLLXy0981PCCgHPpbVy7wjEqx_V54r_b_pSyAH0JvgQ@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Richard Smith <richard@metafoo.co.uk>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Fixing the private method issue
Date: Mon, 4 Nov 2013 14:17:24 -0800
Lines: 198
Approved: news@gmane.org
Message-ID: <CAOfiQqkxLLXy0981PCCgHPpbVy7wjEqx_V54r_b_pSyAH0JvgQ@mail.gmail.com>
References: <d5cd9fa5-ac2f-465b-b92d-cf2a35607245@isocpp.org>
	<5eeafd6f-32f3-4281-9374-617af852fe21@isocpp.org>
	<CAOfiQqkokv_B9JDrGGviBM3-yScSCMTjS5wMd49dQpwinPBiWA@mail.gmail.com>
	<CAGsORuAspU5wOfv44_pDj01Nj9eVyWPUHYj73jJAqsNTXobx=Q@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=001a11c1c4a6d713ee04ea61473f
X-Trace: ger.gmane.org 1383603442 9484 80.91.229.3 (4 Nov 2013 22:17:22 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 4 Nov 2013 22:17:22 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDVNBJG4YAIBB5NZ4CJQKGQEJ3FMODY@isocpp.org Mon Nov 04 23:17:28 2013
Return-path: <std-proposals+bncBDVNBJG4YAIBB5NZ4CJQKGQEJ3FMODY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ie0-f197.google.com ([209.85.223.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDVNBJG4YAIBB5NZ4CJQKGQEJ3FMODY@isocpp.org>)
	id 1VdSSc-00015u-WE
	for gclcip-std-proposals@m.gmane.org; Mon, 04 Nov 2013 23:17:27 +0100
Original-Received: by mail-ie0-f197.google.com with SMTP id e14sf23331246iej.0
        for <gclcip-std-proposals@m.gmane.org>; Mon, 04 Nov 2013 14:17:26 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:sender:in-reply-to:references:date
         :message-id:subject:from:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=A3JPx77hOXG3dRvU9RmByCi9kZPOZaU88PlFMC9PNr0=;
        b=CyEyOjAygFyN6AlyGZ+Q3emn0fSK3Z/wmK256OtFjOmGMZtr9wFa5MXuvHAE5t2VDC
         /Gzs0mGpAUKuQdetvlAFJ63TZylahPRnGRTtNDGV2hyF5xjXA5x4HKaSi4FM7vEMG5Tl
         JqV90/xWZxltiNt/dU3XhIcVxv1llGyAWweGWXYpPKWv0m2FmgVZxhCmO4io+4lg5Pya
         m4MjFudP/h9SgLrc0bsNzBqfUnjAmsPhIcu3lFl6BE7KOe5+398AYHp+/8icfqNCez4I
         twq2yUapPko6xoGRTNvt/yHHxy2NLAv44X/OY8kiyWf5UdG8hvSIiz+JbQmIuYJjRJxX
         P6NQ==
X-Gm-Message-State: ALoCoQkcHMx0QePypO4txWKKc2Z5JNwSLRraLfZVAvudImyxlQueHhPxcmRV5qPeJRkgMTZVreDZ
X-Received: by 10.182.126.137 with SMTP id my9mr6415052obb.13.1383603446099;
        Mon, 04 Nov 2013 14:17:26 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.51.40 with SMTP id h8ls2558181qeo.28.gmail; Mon, 04 Nov
 2013 14:17:25 -0800 (PST)
X-Received: by 10.52.34.109 with SMTP id y13mr11256534vdi.8.1383603445234;
        Mon, 04 Nov 2013 14:17:25 -0800 (PST)
Original-Received: from mail-vc0-x234.google.com (mail-vc0-x234.google.com [2607:f8b0:400c:c03::234])
        by mx.google.com with ESMTPS id j1si5500334vci.26.2013.11.04.14.17.25
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Mon, 04 Nov 2013 14:17:25 -0800 (PST)
Received-SPF: pass (google.com: domain of metafoo@gmail.com designates 2607:f8b0:400c:c03::234 as permitted sender) client-ip=2607:f8b0:400c:c03::234;
Original-Received: by mail-vc0-f180.google.com with SMTP id lc6so5159155vcb.11
        for <std-proposals@isocpp.org>; Mon, 04 Nov 2013 14:17:24 -0800 (PST)
X-Received: by 10.52.243.138 with SMTP id wy10mr11056762vdc.2.1383603444811;
 Mon, 04 Nov 2013 14:17:24 -0800 (PST)
Original-Sender: metafoo@gmail.com
Original-Received: by 10.58.100.145 with HTTP; Mon, 4 Nov 2013 14:17:24 -0800 (PST)
In-Reply-To: <CAGsORuAspU5wOfv44_pDj01Nj9eVyWPUHYj73jJAqsNTXobx=Q@mail.gmail.com>
X-Original-Sender: richard@metafoo.co.uk
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of metafoo@gmail.com designates 2607:f8b0:400c:c03::234 as permitted
 sender) smtp.mail=metafoo@gmail.com;       dkim=pass header.i=@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:7597
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/7597>

--001a11c1c4a6d713ee04ea61473f
Content-Type: text/plain; charset=ISO-8859-1

On Mon, Nov 4, 2013 at 12:36 PM, Zhihao Yuan <zy@miator.net> wrote:

> On Mon, Nov 4, 2013 at 1:01 PM, Richard Smith <richard@metafoo.co.uk>
> wrote:
> >> //foo.cc:
> >>
> >> class Foo namespace {
> >
> >
> > "class X namespace" looks a lot like "allow me to violate access control
> > here, please".
>
> I don't think so.  This scope, afaics, is private, with contents safe
> to be added without changing the ABI.


If you can add friends to a 'class namespace', you can trivially use it to
violate access control (and get access to private members from some third
party TU). You can get the same effect even without allowing friends in a
'class namespace', but you need to work a little harder. For instance:

struct Launderer {
  virtual int get(Foo *p) = 0;
} *launderer;

class Foo namespace {
  struct FooLaunderer : Launderer {
    FooLaunderer() { launderer = this; }
    int get(Foo *p) { return p->_f; }
  } static theLaunderer;
}
Foo::FooLaunderer Foo::theLaunderer;

int evil_get_member(Foo *p) { return launderer->get(p); }

You can get the same effect without a static data member in the 'class
namespace', but again it takes a little more work. And you can do the same
thing without even using a member class (using a local class instead of a
member function instead). So: this subtly breaks access control.

> But since we're brainstorming here, we can get most of the benefit here
> with
> > extension methods alone:
> >
> > // foo.h
> > class Foo {
> > public:
> >   void doWork();
> > private:
> >   int _f;
> >   friend struct FooImpl;
> > };
> >
> > // foo.cc
> > struct FooImpl {
> >   static void doWorkHelper(Foo *this) {
> >     doSomethingWith(_f);
> >   }
> > };
> >
> > void Foo::doWork() {
> >   doWorkHelper();
> > }
>
> I see two problems here:
>
>  1. Program is written for human to read.  This approach, with
>     functions taking pointer to objects, basically reverted C++ to C;
>
>  2. Friend is flawed: what you need is to grant accessibility to
>     a set of functions, but what you do is to grant accessibility to
>     another class scope.  I read this as another "solution from
>     implementation's view" like using private to make a class
>     non-copyable.
>
> There should be more simple, more obvious answer to the problem
> raise in this thread.


*shrug* It doesn't seem like a big problem to me, especially not once we
have modules. I don't think it warrants a big heavy language feature of its
own.

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--001a11c1c4a6d713ee04ea61473f
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Mon, Nov 4, 2013 at 12:36 PM, Zhihao Yuan <span dir=3D"=
ltr">&lt;<a href=3D"mailto:zy@miator.net" target=3D"_blank">zy@miator.net</=
a>&gt;</span> wrote:<br><div class=3D"gmail_extra"><div class=3D"gmail_quot=
e"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left=
:1px #ccc solid;padding-left:1ex">
<div class=3D"im">On Mon, Nov 4, 2013 at 1:01 PM, Richard Smith &lt;<a href=
=3D"mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>&gt; wrote:<br>
&gt;&gt; //foo.cc:<br>
&gt;&gt;<br>
&gt;&gt; class Foo namespace {<br>
&gt;<br>
&gt;<br>
&gt; &quot;class X namespace&quot; looks a lot like &quot;allow me to viola=
te access control<br>
&gt; here, please&quot;.<br>
<br>
</div>I don&#39;t think so. =A0This scope, afaics, is private, with content=
s safe<br>
to be added without changing the ABI.</blockquote><div><br></div><div>If yo=
u can add friends to a &#39;class namespace&#39;, you can trivially use it =
to violate access control (and get access to private members from some thir=
d party TU). You can get the same effect even without allowing friends in a=
 &#39;class namespace&#39;, but you need to work a little harder. For insta=
nce:</div>
<div><br></div><div>struct Launderer {<br></div><div>=A0 virtual int get(Fo=
o *p) =3D 0;</div><div>} *launderer;<br></div><div><br></div><div>class Foo=
 namespace {<br></div><div>=A0 struct FooLaunderer : Launderer {</div><div>=
=A0 =A0 FooLaunderer() { launderer =3D this; }</div>
<div>=A0 =A0 int get(Foo *p) { return p-&gt;_f; }</div><div>=A0 } static th=
eLaunderer;</div><div>}</div><div>Foo::FooLaunderer Foo::theLaunderer;</div=
><div><br></div><div>int evil_get_member(Foo *p) { return launderer-&gt;get=
(p); }</div>
<div><br></div><div>You can get the same effect without a static data membe=
r in the &#39;class namespace&#39;, but again it takes a little more work. =
And you can do the same thing without even using a member class (using a lo=
cal class instead of a member function instead). So: this subtly breaks acc=
ess control.</div>
<div><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex=
;border-left:1px #ccc solid;padding-left:1ex"><div class=3D"im">
&gt; But since we&#39;re brainstorming here, we can get most of the benefit=
 here with<br>
&gt; extension methods alone:<br>
&gt;<br>
&gt; // foo.h<br>
&gt; class Foo {<br>
&gt; public:<br>
&gt; =A0 void doWork();<br>
&gt; private:<br>
&gt; =A0 int _f;<br>
&gt; =A0 friend struct FooImpl;<br>
&gt; };<br>
&gt;<br>
&gt; // foo.cc<br>
&gt; struct FooImpl {<br>
&gt; =A0 static void doWorkHelper(Foo *this) {<br>
&gt; =A0 =A0 doSomethingWith(_f);<br>
&gt; =A0 }<br>
&gt; };<br>
&gt;<br>
&gt; void Foo::doWork() {<br>
&gt; =A0 doWorkHelper();<br>
&gt; }<br>
<br>
</div>I see two problems here:<br>
<br>
=A01. Program is written for human to read. =A0This approach, with<br>
=A0 =A0 functions taking pointer to objects, basically reverted C++ to C;<b=
r>
<br>
=A02. Friend is flawed: what you need is to grant accessibility to<br>
=A0 =A0 a set of functions, but what you do is to grant accessibility to<br=
>
=A0 =A0 another class scope. =A0I read this as another &quot;solution from<=
br>
=A0 =A0 implementation&#39;s view&quot; like using private to make a class<=
br>
=A0 =A0 non-copyable.<br>
<br>
There should be more simple, more obvious answer to the problem<br>
raise in this thread.</blockquote><div><br></div><div>*shrug* It doesn&#39;=
t seem like a big problem to me, especially not once we have modules. I don=
&#39;t think it warrants a big heavy language feature of its own.</div>
</div></div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--001a11c1c4a6d713ee04ea61473f--

.
