220 38947 <fe3a7806-ec9f-4822-bd79-2d6d61b97c43@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Allow forward class declarations to match a type alias.
Date: Sat, 30 Jun 2018 15:04:00 -0700 (PDT)
Lines: 158
Approved: news@gmane.org
Message-ID: <fe3a7806-ec9f-4822-bd79-2d6d61b97c43@isocpp.org>
References: <b2fb570b-aadb-423e-9821-025cb447cf60@isocpp.org>
 <CAC+0CCMRC5JHx4N2JFzN960xfYsBVfKVt=7iSN5NCws3ALHkFA@mail.gmail.com>
 <a4d20e97-3563-43c3-a1f9-a7b2e57276b4@isocpp.org>
 <49cde8d1-312f-4c4c-a26e-91bbb1c56a2d@isocpp.org>
 <abdf6051-28fa-48e6-81c6-20eff0a2d4de@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_25301_676648564.1530396240632"
X-Trace: blaine.gmane.org 1530396116 26246 195.159.176.226 (30 Jun 2018 22:01:56 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 30 Jun 2018 22:01:56 +0000 (UTC)
Cc: mihailnajdenov@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBUP437MQKGQEQXQODTA@isocpp.org Sun Jul 01 00:01:51 2018
Return-path: <std-proposals+bncBCEKFTV6ZUMBBUP437MQKGQEQXQODTA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yb0-f199.google.com ([209.85.213.199])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBBUP437MQKGQEQXQODTA@isocpp.org>)
	id 1fZNwF-0006jJ-1s
	for gclcip-std-proposals@m.gmane.org; Sun, 01 Jul 2018 00:01:51 +0200
Original-Received: by mail-yb0-f199.google.com with SMTP id q12-v6sf7978965ybp.11
        for <gclcip-std-proposals@m.gmane.org>; Sat, 30 Jun 2018 15:04:02 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=WQhulF2M7aehQERR/0GyWf56BmfIccs4/YDLqEY3GfM=;
        b=vWLZIdcqr3zFsXuUmbOh+cuUEPzK6KqYqE9inO+/2IfdPoT1JcPldfo5NBX9TLFI1p
         mnG+5P3e0QCmfaaGtawVI9p5YoTvZ0p665WLUxQuZEKAb94bUtoT2VR9gGj++AFAOa+7
         ZwLB3BcTF5muWk0ja48MUS1KAvay5+i1foYRRqFiKcSC8vrqqZCfgIaANKBt/mELOQCH
         FUpdMsGcxIzsPBQVXRXDz1eacu6T9/UEn2WHTLiZ9vCYLXYKxAEVCl4SI/gaQvv4uVvl
         aHk3wZxRJjuu2aHUEfPfu+cy9G/+/HNUjmYeoOvZFOucUprBfXwx3thM9wuiZOPFST7S
         WeVA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=WQhulF2M7aehQERR/0GyWf56BmfIccs4/YDLqEY3GfM=;
        b=dj364jZK11AUiKyyUxyepAPnifsxYL/FKAUo+J4O5nG4TyWsqmzu1eQxdyz0dCaGDh
         MjIbeuXJw6qeViKDxOhA6PrMr62nDwPqnjHmVr5WMkDaG1EhgBIoIo/tsMuvRxDHDX/R
         dqm8+ekx0mLTEby5TPKI0ry6uh4mJiyDM0NkgqoklwGBYnrXKtJhon9TtQ/cvdWDqID1
         0+Et12IOxjNEkiyE3slQ8sfDyP9BvXuPnsgb9AvHmAmm+dYRa41JGuWvhVzOu7+DddvT
         myTnQBCe9kYBIbLIvzDpTuErM9TpQMHsSmnWJs311z7x0dTbIs4Xlr+1O6wkHmrGOTy2
         svDg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:x-original-sender:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=WQhulF2M7aehQERR/0GyWf56BmfIccs4/YDLqEY3GfM=;
        b=ZlRZJti1HPeWVTCmo+IaZd+Q5uuqyV7Ba99rJzCeBGx1IEWhmts40JOGVv6htWL9IE
         2p2BYcR92N/+5SWH+e59OiY397PIedjD8O3AhjhXQiVuunZRz8I4Uau24hRxfQgQ1WyS
         0N7+/aLPxn24tmFollbjpixqvBSyyRzvzQoBQNXcvPG18wpkf+WEDdwFY3xwrx2h4M6y
         ENQLSGOXoafz2Qnlf2keltlWyxg/lA44LDQY0737ez7H+CiaAshpmKOFtYxDkGsZuioj
         8v2TQMe53FA6GOu8r4Smdd2WYRIsBoyISyBkFmrgPn1k2NHLQ9CewAVToKzFyFKhWiOX
         xjew==
X-Gm-Message-State: APt69E0Tpo95xuEeutRJ1VbLzaF16+OXH00NilfcO7Q4ejPBwKeYLoQw
	ej9/OAmYBM4Aw5h1xOsbD99PFg==
X-Google-Smtp-Source: AAOMgpfkLXKXkwz21pPoRi7V5GX8PWIyWsbCc/in9ejVB3Ym3sikw5m1AHMhEtvvx3CPzI0fCPkRZA==
X-Received: by 2002:a81:4b90:: with SMTP id y138-v6mr6513057ywa.186.1530396242060;
        Sat, 30 Jun 2018 15:04:02 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a81:a906:: with SMTP id g6-v6ls2307598ywh.22.gmail; Sat, 30
 Jun 2018 15:04:01 -0700 (PDT)
X-Received: by 2002:a81:9ac4:: with SMTP id r187-v6mr1948719ywg.4.1530396241219;
        Sat, 30 Jun 2018 15:04:01 -0700 (PDT)
In-Reply-To: <abdf6051-28fa-48e6-81c6-20eff0a2d4de@isocpp.org>
X-Original-Sender: jmckesson@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:38947
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/38947>

------=_Part_25301_676648564.1530396240632
Content-Type: multipart/alternative; 
	boundary="----=_Part_25302_7456484.1530396240632"

------=_Part_25302_7456484.1530396240632
Content-Type: text/plain; charset="UTF-8"



On Saturday, June 30, 2018 at 4:23:41 PM UTC-4, Bengt Gustafsson wrote:
>
> In my previous response I acknowedged the explanation that this has to do 
> with name mangling, where ultimately the class name would be mangled 
> according to its real identity, i.e. CudaImage<float> and thus that a 
> forward declaration "class FloatImage;" would be natural to reject.
>
> However, on second thought, FloatImage just as any class name is not an 
> entity in itself that is known to the linker. And as you can't call methods 
> on a class without seeing its full definition there is no risk that 
> references to erroneously mangled method names sneak in to an object module 
> compiled only seeing the forward declaration, right?
>

With only a forward declaration, you cannot call members. Nor can you call 
non-member functions that take a reference to the forward declared type 
(because you would need a valid reference to a `FloatImage`). However, you 
*can* get a pointer to *functions* that take such types:

void func(const FloatImage &);

using fptr = void(*)(const FloatImage&);

fptr f = func;

You can then take `f` and pass it to some API which *itself* can get 
`FloatImage` objects and pass them to the given function pointer. So the 
compiler needs to know how `f` works on something approaching an ABI level. 
And that means knowing if `FloatImage` is an actual type or a type alias 
(and if so, what it is an alias for).

Also, of course, you can call functions that take a pointer to `FloatImage` 
(you can only pass nullptr, of course). Since pointers are themselves 
typed, and linking needs to tell the difference, ABI name mangling needs to 
know if `FloatImage` is a type or a type alias.
 

> With this in mind, is there a technical reason that 
> my initial construct must be forbidden? I don't see that Nicol's 
> explanation holds "FloatImage turns out eventually to be a type alias and 
> not a class". But the very reason for having a type alias is to give a 
> class another name, so why can't it be forward declared under this 
> alternate name?
>

No, the reason to have a type alias is to give a *type* another name. 
`class FloatImage` will always be a *class*. `using FloatImage = ...;` is 
whatever `...` happens to be.

Your initial construct ought to be forbidden because it is incoherent. You 
declared that there is a class named `FloatImage`. You cannot later change 
your mind and decide that it is something else.

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/fe3a7806-ec9f-4822-bd79-2d6d61b97c43%40isocpp.org.

------=_Part_25302_7456484.1530396240632
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Saturday, June 30, 2018 at 4:23:41 PM UTC-4, Be=
ngt Gustafsson wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr">In my previous response I acknowedged the explanation that this ha=
s to do with name mangling, where ultimately the class name would be mangle=
d according to its real identity, i.e. CudaImage&lt;float&gt; and thus that=
 a forward declaration &quot;class FloatImage;&quot; would be natural to re=
ject.<div><br>However, on second thought, FloatImage just as any class name=
 is not an entity in itself that is known to the linker. And as you can&#39=
;t call methods on a class without seeing its full definition there is no r=
isk that references to erroneously mangled method names sneak in to an obje=
ct module compiled only seeing the forward declaration, right?</div></div><=
/blockquote><div><br></div><div></div><div>With only a forward declaration,=
 you cannot call members. Nor can you call non-member functions that take a=
 reference to the forward declared type (because you would need a valid ref=
erence to a `FloatImage`). However, you <i>can</i> get a pointer to <i>func=
tions</i> that take such types:</div><div><br></div><div style=3D"backgroun=
d-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style=
: solid; border-width: 1px; overflow-wrap: break-word;" class=3D"prettyprin=
t"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D=
"color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> func</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">FloatImage</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>&amp;);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">usin=
g</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> fptr </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">(*)(</span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">const</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D=
"styled-by-prettify">FloatImage</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">&amp;);</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br><br>fptr f </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> func</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">;</span></div></code></div><div><br></div><div></div><div>You c=
an then take `f` and pass it to some API which <i>itself</i> can get `Float=
Image` objects and pass them to the given function pointer. So the compiler=
 needs to know how `f` works on something approaching an ABI level. And tha=
t means knowing if `FloatImage` is an actual type or a type alias (and if s=
o, what it is an alias for).</div><div><br></div><div>Also, of course, you =
can call functions that take a pointer to `FloatImage` (you can only pass n=
ullptr, of course). Since pointers are themselves typed, and linking needs =
to tell the difference, ABI name mangling needs to know if `FloatImage` is =
a type or a type alias.<br></div><div>=C2=A0</div><blockquote class=3D"gmai=
l_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;=
padding-left: 1ex;"><div dir=3D"ltr"><div>With this in mind, is there a tec=
hnical reason that=C2=A0</div><div><div>my initial construct must be forbid=
den? I don&#39;t see that Nicol&#39;s explanation holds &quot;FloatImage tu=
rns out eventually to be a type alias and not a class&quot;. But the very r=
eason for having a type alias is to give a class another name, so why can&#=
39;t it be forward declared under this alternate name?</div></div></div></b=
lockquote><div><br></div><div>No, the reason to have a type alias is to giv=
e a <i>type</i> another name. `class FloatImage` will always be a <i>class<=
/i>. `using FloatImage =3D ...;` is whatever `...` happens to be.</div><div=
><br></div><div>Your initial construct ought to be forbidden because it is =
incoherent. You declared that there is a class named `FloatImage`. You cann=
ot later change your mind and decide that it is something else.</div><br></=
div>

<p></p>

-- <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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/fe3a7806-ec9f-4822-bd79-2d6d61b97c43%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/fe3a7806-ec9f-4822-bd79-2d6d61b97c43=
%40isocpp.org</a>.<br />

------=_Part_25302_7456484.1530396240632--

------=_Part_25301_676648564.1530396240632--

.
