Topic: [RFC] Implicit Return Type and Allowing
Author: "D. B." <db0451@gmail.com>
Date: Sat, 17 Dec 2016 23:22:11 +0000
Raw View
--047d7b86e2f8c9a15e0543e2f47a
Content-Type: text/plain; charset=UTF-8
On Sat, Dec 17, 2016 at 11:06 PM, Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
wrote:
> The following kind of "anonymous type as return type" is already fully
> supported in C++14:
>
> auto f() { struct { int x, y; } s; return s; }
>
> You're proposing to go beyond that, with
>
> struct { int x, y; } f() { ??? s; return s; }
>
> where you additionally want-but-explicitly-do-not-propose
> "decltype(return)" as the appropriate syntax for "???".
>
> I think this proposal adds *consistency* to the language, but doesn't add
> any functionality that working programmers should actually desire.
>
Not that I want to take a side either way, but for whatever reason that
someone would want the syntax in the 1st example above, they wouldn't be
able to use it if the function was declared other than where it was
defined. That, presumably, is a key rationale for *decltype(return)* or
whatever we want to call it.
--
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/CACGiwhF22pto0aZU3OqJEq-%3Ds2d45t_82FCi_-jCCgi681WpQg%40mail.gmail.com.
--047d7b86e2f8c9a15e0543e2f47a
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><div class=3D"gmail_extra"><div class=3D"gmail_quote">=
On Sat, Dec 17, 2016 at 11:06 PM, Arthur O'Dwyer <span dir=3D"ltr"><=
<a href=3D"mailto:arthur.j.odwyer@gmail.com" target=3D"_blank">arthur.j.odw=
yer@gmail.com</a>></span> wrote:<br><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>=
<span class=3D""></span>The following kind of "anonymous type as retur=
n type" is already fully supported in C++14:<div><br></div><div class=
=3D"m_-7253182601477058007prettyprint" style=3D"background-color:rgb(250,25=
0,250);border:1px solid rgb(187,187,187);word-wrap:break-word"><code class=
=3D"m_-7253182601477058007prettyprint"><div class=3D"m_-7253182601477058007=
subprettyprint"><span style=3D"color:#008" class=3D"m_-7253182601477058007s=
tyled-by-prettify">auto</span><span style=3D"color:#000" class=3D"m_-725318=
2601477058007styled-by-prettify"> f</span><span style=3D"color:#660" class=
=3D"m_-7253182601477058007styled-by-prettify">()</span><span style=3D"color=
:#000" class=3D"m_-7253182601477058007styled-by-prettify"> </span><span sty=
le=3D"color:#660" class=3D"m_-7253182601477058007styled-by-prettify">{</spa=
n><span style=3D"color:#000" class=3D"m_-7253182601477058007styled-by-prett=
ify"> </span><span style=3D"color:#008" class=3D"m_-7253182601477058007styl=
ed-by-prettify">struct</span><span style=3D"color:#000" class=3D"m_-7253182=
601477058007styled-by-prettify"> </span><span style=3D"color:#660" class=3D=
"m_-7253182601477058007styled-by-prettify">{</span><span style=3D"color:#00=
0" class=3D"m_-7253182601477058007styled-by-prettify"> </span><span style=
=3D"color:#008" class=3D"m_-7253182601477058007styled-by-prettify">int</spa=
n><span style=3D"color:#000" class=3D"m_-7253182601477058007styled-by-prett=
ify"> x</span><span style=3D"color:#660" class=3D"m_-7253182601477058007sty=
led-by-prettify">,</span><span style=3D"color:#000" class=3D"m_-72531826014=
77058007styled-by-prettify"> y</span><span style=3D"color:#660" class=3D"m_=
-7253182601477058007styled-by-prettify">;</span><span style=3D"color:#000" =
class=3D"m_-7253182601477058007styled-by-prettify"> </span><span style=3D"c=
olor:#660" class=3D"m_-7253182601477058007styled-by-prettify">}</span><span=
style=3D"color:#000" class=3D"m_-7253182601477058007styled-by-prettify"> s=
</span><span style=3D"color:#660" class=3D"m_-7253182601477058007styled-by-=
prettify">;</span><span style=3D"color:#000" class=3D"m_-725318260147705800=
7styled-by-prettify"> </span><span style=3D"color:#008" class=3D"m_-7253182=
601477058007styled-by-prettify">return</span><span style=3D"color:#000" cla=
ss=3D"m_-7253182601477058007styled-by-prettify"> s</span><span style=3D"col=
or:#660" class=3D"m_-7253182601477058007styled-by-prettify">;</span><span s=
tyle=3D"color:#000" class=3D"m_-7253182601477058007styled-by-prettify"> </s=
pan><span style=3D"color:#660" class=3D"m_-7253182601477058007styled-by-pre=
ttify">}</span><span style=3D"color:#000" class=3D"m_-7253182601477058007st=
yled-by-prettify"><br></span></div></code></div><div><br></div><div>You'=
;re proposing to go beyond that, with</div><div><br></div><div class=3D"m_-=
7253182601477058007prettyprint" style=3D"background-color:rgb(250,250,250);=
border:1px solid rgb(187,187,187);word-wrap:break-word"><code class=3D"m_-7=
253182601477058007prettyprint"><div class=3D"m_-7253182601477058007subprett=
yprint"><span style=3D"color:#008" class=3D"m_-7253182601477058007styled-by=
-prettify">struct</span><span style=3D"color:#000" class=3D"m_-725318260147=
7058007styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_-7=
253182601477058007styled-by-prettify">{</span><span style=3D"color:#000" cl=
ass=3D"m_-7253182601477058007styled-by-prettify"> </span><span style=3D"col=
or:#008" class=3D"m_-7253182601477058007styled-by-prettify">int</span><span=
style=3D"color:#000" class=3D"m_-7253182601477058007styled-by-prettify"> x=
</span><span style=3D"color:#660" class=3D"m_-7253182601477058007styled-by-=
prettify">,</span><span style=3D"color:#000" class=3D"m_-725318260147705800=
7styled-by-prettify"> y</span><span style=3D"color:#660" class=3D"m_-725318=
2601477058007styled-by-prettify">;</span><span style=3D"color:#000" class=
=3D"m_-7253182601477058007styled-by-prettify"> </span><span style=3D"color:=
#660" class=3D"m_-7253182601477058007styled-by-prettify">}</span><span styl=
e=3D"color:#000" class=3D"m_-7253182601477058007styled-by-prettify"> f</spa=
n><span style=3D"color:#660" class=3D"m_-7253182601477058007styled-by-prett=
ify">()</span><span style=3D"color:#000" class=3D"m_-7253182601477058007sty=
led-by-prettify"> </span><span style=3D"color:#660" class=3D"m_-72531826014=
77058007styled-by-prettify">{</span><span style=3D"color:#000" class=3D"m_-=
7253182601477058007styled-by-prettify"> </span><span style=3D"color:#660" c=
lass=3D"m_-7253182601477058007styled-by-prettify">???</span><span style=3D"=
color:#000" class=3D"m_-7253182601477058007styled-by-prettify"> s</span><sp=
an style=3D"color:#660" class=3D"m_-7253182601477058007styled-by-prettify">=
;</span><span style=3D"color:#000" class=3D"m_-7253182601477058007styled-by=
-prettify"> </span><span style=3D"color:#008" class=3D"m_-72531826014770580=
07styled-by-prettify">return</span><span style=3D"color:#000" class=3D"m_-7=
253182601477058007styled-by-prettify"> s</span><span style=3D"color:#660" c=
lass=3D"m_-7253182601477058007styled-by-prettify">;</span><span style=3D"co=
lor:#000" class=3D"m_-7253182601477058007styled-by-prettify"> </span><span =
style=3D"color:#660" class=3D"m_-7253182601477058007styled-by-prettify">}</=
span><span style=3D"color:#000" class=3D"m_-7253182601477058007styled-by-pr=
ettify"><br></span></div></code></div><div><br></div><div>where you additio=
nally want-but-explicitly-do-not-<wbr>propose "decltype(return)" =
as the appropriate syntax for "???".</div><div><br></div><div>I t=
hink this proposal adds <i>consistency</i> to the language, but doesn't=
add any functionality that working programmers should actually desire.=C2=
=A0</div></div></blockquote><div><br><br></div><div>Not that I want to take=
a side either way, but for whatever reason that someone would want the syn=
tax in the 1st example above, they wouldn't be able to use it if the fu=
nction was declared other than where it was defined. That, presumably, is a=
key rationale for <i>decltype(return)</i> or whatever we want to call it.<=
br>=C2=A0<br></div></div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/CACGiwhF22pto0aZU3OqJEq-%3Ds2d45t_82F=
Ci_-jCCgi681WpQg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhF22pto0a=
ZU3OqJEq-%3Ds2d45t_82FCi_-jCCgi681WpQg%40mail.gmail.com</a>.<br />
--047d7b86e2f8c9a15e0543e2f47a--
.
Author: "Arthur O'Dwyer" <arthur.j.odwyer@gmail.com>
Date: Sat, 17 Dec 2016 17:10:46 -0800
Raw View
--001a11483e46216eb30543e47973
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Sat, Dec 17, 2016 at 4:11 PM, Nicol Bolas <jmckesson@gmail.com> wrote:
> On Saturday, December 17, 2016 at 6:06:33 PM UTC-5, Arthur O'Dwyer wrote:
>>
>>
>>> struct { int x, y; } f() { ??? s; return s; }
>>
>> where you additionally want-but-explicitly-do-not-propose
>> "decltype(return)" as the appropriate syntax for "???".
>>
>
> Not really. The idea being that you'd just do `return {};`. You would onl=
y
> need `decltype(return)` if you needed to declare a variable of the return
> type.
>
> If you're using these anonymous structs as a way to do multiple return
> values without tuples, then you don't really need the return type itself.
> So the proposal is genuinely useful independently of `decltype(return)` t=
o
> fetch the function's return type.
>
True, I was too cartoonish there; but I stand by my assertion that I
wouldn't want this feature (in fact I'd hope for an opt-in compiler
diagnostic on this feature) in my own codebases.
> The second, more important =E2=80=94 possibly killer? =E2=80=94 problem i=
s also
>> illustrated by the above program: what does the following declaration(?)
>> actually declare?
>>
>> template<class T>
>> struct {
>> int s;
>> }
>> tomorrow(T t) {
>> return {sizeof t};
>> }
>>
>> All the way until the first closing curly brace on line 4 =E2=80=94 i.e.=
all
>> during the parsing of the struct body =E2=80=94 this *looks* like a clas=
s
>> template definition.
>>
>
> Does it? Because I'm fairly certain that class templates cannot be
> declared without a name <http://ideone.com/vRQusf>. That's not
> definitive; I wouldn't know where to start looking through the standard f=
or
> this. But I'm pretty sure it can't happen; how would you instantiate one?
>
You're right. But then maybe Matthew's proposal isn't adding as much
consistency as I thought =E2=80=94 in that the current state of affairs isn=
't as
consistent as I'd thought. After some experimentation, I gather that today
the situation is:
struct { } v1; // OK in C++98
struct S { } v2; // OK in C++98: declares both S and v2
struct { } f1() { return {}; } // ERROR in C++98
struct S { } f2() { return {}; } // ERROR in C++98
template<class T> struct { } vt1; // ERROR in C++14: a template must have
a name, and can't also declare vt1
template<class T> struct S { } vt2; // ERROR in C++14: definition of S<T>
can't also declare vt2
template<class T> struct { } ft1(); // ERROR in C++98: a template must
have a name, and can't also declare ft1
template<class T> struct S { } ft2(); // ERROR in C++98: definition of
S<T> can't also declare ft2
Matthew 's proposal makes it this:
struct { } v1; // OK in C++98
struct S { } v2; // OK in C++98: declares both S and v2
struct { } f1() { return {}; } // OK in proposal
struct S { } f2() { return {}; } // UNKNOWN in proposal: presumably should
declare both S and f2
template<class T> struct { } vt1; // ERROR in C++14: a template must have
a name, and can't also declare vt1
template<class T> struct S { } vt2; // ERROR in C++14: definition of S<T>
can't also declare vt2
template<class T> struct { } ft1(); // ERROR in C++98: a template must
have a name, and can't also declare ft1
template<class T> struct S { } ft2(); // ERROR in C++98: definition of
S<T> can't also declare ft2
The proposal should explicitly cover the "f2" case above; and if the intent
is to support that case, then it should maybe not make such a big deal
about "anonymous" types. The real issue here is just whether C++ should
permit defining a new class type in the same declaration as various other
kinds of entities (variables and typedefs yes, functions currently no). I
think it would be a bad idea to support such declarations *only* when the
new class type is anonymous.
HTH,
=E2=80=93Arthur
--=20
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 e=
mail 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/CADvuK0%2BotmMfpONBtKkhuNDbztitBzQYYK3x0b3sq7aAn=
7u7fw%40mail.gmail.com.
--001a11483e46216eb30543e47973
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Sat, Dec 17, 2016 at 4:11 PM, Nicol Bolas <span dir=3D"=
ltr"><<a href=3D"mailto:jmckesson@gmail.com" target=3D"_blank">jmckesson=
@gmail.com</a>></span> wrote:<br><div class=3D"gmail_extra"><div class=
=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px =
0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-l=
eft-style:solid;padding-left:1ex"><div dir=3D"ltr"><span class=3D"gmail-">O=
n Saturday, December 17, 2016 at 6:06:33 PM UTC-5, Arthur O'Dwyer wrote=
:<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border=
-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;=
padding-left:1ex"><div dir=3D"ltr"><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(20=
4,204,204);border-left-style:solid;padding-left:1ex"><br></blockquote><div =
style=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,187,187=
);word-wrap:break-word"><code><div><span style=3D"color:rgb(0,0,136)">struc=
t</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(1=
02,102,0)">{</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"=
color:rgb(0,0,136)">int</span><span style=3D"color:rgb(0,0,0)"> x</span><sp=
an style=3D"color:rgb(102,102,0)">,</span><span style=3D"color:rgb(0,0,0)">=
y</span><span style=3D"color:rgb(102,102,0)">;</span><span style=3D"color:=
rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">}</span><span styl=
e=3D"color:rgb(0,0,0)"> f</span><span style=3D"color:rgb(102,102,0)">()</sp=
an><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,10=
2,0)">{</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color=
:rgb(102,102,0)">???</span><span style=3D"color:rgb(0,0,0)"> s</span><span =
style=3D"color:rgb(102,102,0)">;</span><span style=3D"color:rgb(0,0,0)"> </=
span><span style=3D"color:rgb(0,0,136)">return</span><span style=3D"color:r=
gb(0,0,0)"> s</span><span style=3D"color:rgb(102,102,0)">;</span><span styl=
e=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">}</span=
><span style=3D"color:rgb(0,0,0)"><br></span></div></code></div><div><br></=
div><div>where you additionally want-but-explicitly-do-not-pro<wbr>pose &qu=
ot;decltype(return)" as the appropriate syntax for "???".</d=
iv></div></blockquote></span><div><br>Not really. The idea being that you&#=
39;d just do `return {};`. You would only need `decltype(return)` if you ne=
eded to declare a variable of the return type.<br><br>If you're using t=
hese anonymous structs as a way to do multiple return values without tuples=
, then you don't really need the return type itself. So the proposal is=
genuinely useful independently of `decltype(return)` to fetch the function=
's return type.<br></div></div></blockquote><div><br></div><div>True, I=
was too cartoonish there; but I stand by my assertion that I wouldn't =
want this feature (in fact I'd hope for an opt-in compiler diagnostic o=
n this feature) in my own codebases.</div><div>=C2=A0</div><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;b=
order-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"=
><div dir=3D"ltr"><span class=3D"gmail-"><blockquote class=3D"gmail_quote" =
style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:r=
gb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir=3D"ltr">=
<div>The second, more important =E2=80=94 possibly killer? =E2=80=94 proble=
m is also illustrated by the above program: what does the following declara=
tion(?) actually declare?</div><div><br></div><div style=3D"background-colo=
r:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap:break-word">=
<code><div><span style=3D"color:rgb(0,0,136)">template</span><span style=3D=
"color:rgb(102,102,0)"><</span><span style=3D"color:rgb(0,0,136)">class<=
/span><span style=3D"color:rgb(0,0,0)"> T</span><span style=3D"color:rgb(10=
2,102,0)">></span><span style=3D"color:rgb(0,0,0)"><br></span><span styl=
e=3D"color:rgb(0,0,136)">struct</span><span style=3D"color:rgb(0,0,0)"> </s=
pan><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0=
,0,0)"><br>=C2=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">int</spa=
n><span style=3D"color:rgb(0,0,0)"> s</span><span style=3D"color:rgb(102,10=
2,0)">;</span><span style=3D"color:rgb(0,0,0)"><br></span><span style=3D"co=
lor:rgb(102,102,0)">}</span><span style=3D"color:rgb(0,0,0)"><br>tomorrow</=
span><span style=3D"color:rgb(102,102,0)">(</span><span style=3D"color:rgb(=
0,0,0)">T t</span><span style=3D"color:rgb(102,102,0)">)</span><span style=
=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">{</span>=
<span style=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 </span><span style=3D"co=
lor:rgb(0,0,136)">return</span><span style=3D"color:rgb(0,0,0)"> </span><sp=
an style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,0,136)=
">sizeof</span><span style=3D"color:rgb(0,0,0)"> t</span><span style=3D"col=
or:rgb(102,102,0)">};</span><span style=3D"color:rgb(0,0,0)"><br></span><sp=
an style=3D"color:rgb(102,102,0)">}</span></div></code></div><div><br></div=
><div>All the way until the first closing curly brace on line 4 =E2=80=94 i=
..e. all during the parsing of the struct body =E2=80=94 this <i>looks</i> l=
ike a class template definition.</div></div></blockquote></span><div><br>Do=
es it? Because I'm <a href=3D"http://ideone.com/vRQusf" target=3D"_blan=
k">fairly certain that class templates cannot be declared without a name</a=
>. That's not definitive; I wouldn't know where to start looking th=
rough the standard for this. But I'm pretty sure it can't happen; h=
ow would you instantiate one?<br></div></div></blockquote><div><br></div><d=
iv>You're right. But then maybe Matthew's proposal isn't adding=
as much consistency as I thought =E2=80=94 in that the current state of af=
fairs isn't as consistent as I'd thought.=C2=A0 After some experime=
ntation, I gather that today the situation is:</div><div><br></div><div>str=
uct { } v1; =C2=A0// OK in C++98</div><div>struct S { } v2; =C2=A0// OK in =
C++98: declares both S and v2</div><div><div>struct { } f1() { return {}; }=
=C2=A0// ERROR in C++98</div><div>struct S { } f2() { return {}; } =C2=A0/=
/ ERROR in C++98</div><div></div></div><div><div>template<class T> st=
ruct { } vt1; =C2=A0// ERROR in C++14: a template must have a name, and can=
't also declare vt1</div></div><div><div>template<class T> struct=
S { } vt2; =C2=A0// ERROR in C++14: definition of S<T> can't als=
o declare vt2</div></div><div><div>template<class T> struct { } ft1()=
; =C2=A0// ERROR in C++98: a template must have a name, and can't also =
declare ft1</div><div>template<class T> struct S { } ft2(); =C2=A0// =
ERROR in C++98: definition of S<T> can't also declare ft2</div></=
div><div><br></div><div>Matthew 's proposal makes it this:</div><div><b=
r></div><div><div>struct { } v1; =C2=A0// OK in C++98</div><div>struct S { =
} v2; =C2=A0// OK in C++98: declares both S and v2</div><div><div>struct { =
} f1() { return {}; } =C2=A0// OK in proposal</div><div>struct S { } f2() {=
return {}; } =C2=A0// UNKNOWN in proposal: presumably should declare both =
S and f2<br></div><div></div></div><div>template<class T> struct { } =
vt1; =C2=A0// ERROR in C++14: a template must have a name, and can't al=
so declare vt1</div><div>template<class T> struct S { } vt2; =C2=A0//=
ERROR in C++14: definition of S<T> can't also declare vt2</div><=
div><div>template<class T> struct { } ft1(); =C2=A0// ERROR in C++98:=
a template must have a name, and can't also declare ft1</div><div>temp=
late<class T> struct S { } ft2(); =C2=A0// ERROR in C++98: definition=
of S<T> can't also declare ft2</div></div><div><br></div></div><=
div>The proposal should explicitly cover the "f2" case above; and=
if the intent is to support that case, then it should maybe not make such =
a big deal about "anonymous" types. The real issue here is just w=
hether C++ should permit defining a new class type in the same declaration =
as various other kinds of entities (variables and typedefs yes, functions c=
urrently no). I think it would be a bad idea to support such declarations <=
i>only</i> when the new class type is anonymous.</div><div><br></div><div>H=
TH,</div><div>=E2=80=93Arthur</div></div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/CADvuK0%2BotmMfpONBtKkhuNDbztitBzQYYK=
3x0b3sq7aAn7u7fw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CADvuK0%2BotmMf=
pONBtKkhuNDbztitBzQYYK3x0b3sq7aAn7u7fw%40mail.gmail.com</a>.<br />
--001a11483e46216eb30543e47973--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sat, 17 Dec 2016 17:56:27 -0800 (PST)
Raw View
------=_Part_994_1006923881.1482026187552
Content-Type: multipart/alternative;
boundary="----=_Part_995_222150544.1482026187553"
------=_Part_995_222150544.1482026187553
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Saturday, December 17, 2016 at 8:10:49 PM UTC-5, Arthur O'Dwyer wrote:
>
> On Sat, Dec 17, 2016 at 4:11 PM, Nicol Bolas <jmck...@gmail.com=20
> <javascript:>> wrote:
>
>> On Saturday, December 17, 2016 at 6:06:33 PM UTC-5, Arthur O'Dwyer wrote=
:
>>>
>>>
>>>> struct { int x, y; } f() { ??? s; return s; }
>>>
>>> where you additionally want-but-explicitly-do-not-propose=20
>>> "decltype(return)" as the appropriate syntax for "???".
>>>
>>
>> Not really. The idea being that you'd just do `return {};`. You would=20
>> only need `decltype(return)` if you needed to declare a variable of the=
=20
>> return type.
>>
>> If you're using these anonymous structs as a way to do multiple return=
=20
>> values without tuples, then you don't really need the return type itself=
..=20
>> So the proposal is genuinely useful independently of `decltype(return)` =
to=20
>> fetch the function's return type.
>>
>
> True, I was too cartoonish there; but I stand by my assertion that I=20
> wouldn't want this feature (in fact I'd hope for an opt-in compiler=20
> diagnostic on this feature) in my own codebases.
>
I'm not exactly happy with the idea of promoting the creation of anonymous=
=20
types myself. But I highly doubt that there will ever be a compiler=20
diagnostic on it. If for no other reason than the fact that there will=20
likely be standard library types that make use of it. You can't just add=20
something to the language, then forbid any standard library components from=
=20
ever making use of it.
The second, more important =E2=80=94 possibly killer? =E2=80=94 problem is =
also illustrated=20
>>> by the above program: what does the following declaration(?) actually=
=20
>>> declare?
>>>
>>> template<class T>
>>> struct {
>>> int s;
>>> }
>>> tomorrow(T t) {
>>> return {sizeof t};
>>> }
>>>
>>> All the way until the first closing curly brace on line 4 =E2=80=94 i.e=
.. all=20
>>> during the parsing of the struct body =E2=80=94 this *looks* like a cla=
ss=20
>>> template definition.
>>>
>>
>> Does it? Because I'm fairly certain that class templates cannot be=20
>> declared without a name <http://ideone.com/vRQusf>. That's not=20
>> definitive; I wouldn't know where to start looking through the standard =
for=20
>> this. But I'm pretty sure it can't happen; how would you instantiate one=
?
>>
>
> You're right. But then maybe Matthew's proposal isn't adding as much=20
> consistency as I thought =E2=80=94 in that the current state of affairs i=
sn't as=20
> consistent as I'd thought. After some experimentation, I gather that tod=
ay=20
> the situation is:
>
> struct { } v1; // OK in C++98
> struct S { } v2; // OK in C++98: declares both S and v2
> struct { } f1() { return {}; } // ERROR in C++98
> struct S { } f2() { return {}; } // ERROR in C++98
> template<class T> struct { } vt1; // ERROR in C++14: a template must hav=
e=20
> a name, and can't also declare vt1
> template<class T> struct S { } vt2; // ERROR in C++14: definition of S<T=
>=20
> can't also declare vt2
> template<class T> struct { } ft1(); // ERROR in C++98: a template must=
=20
> have a name, and can't also declare ft1
> template<class T> struct S { } ft2(); // ERROR in C++98: definition of=
=20
> S<T> can't also declare ft2
>
> Matthew 's proposal makes it this:
>
> struct { } v1; // OK in C++98
> struct S { } v2; // OK in C++98: declares both S and v2
> struct { } f1() { return {}; } // OK in proposal
> struct S { } f2() { return {}; } // UNKNOWN in proposal: presumably=20
> should declare both S and f2
> template<class T> struct { } vt1; // ERROR in C++14: a template must hav=
e=20
> a name, and can't also declare vt1
> template<class T> struct S { } vt2; // ERROR in C++14: definition of S<T=
>=20
> can't also declare vt2
> template<class T> struct { } ft1(); // ERROR in C++98: a template must=
=20
> have a name, and can't also declare ft1
> template<class T> struct S { } ft2(); // ERROR in C++98: definition of=
=20
> S<T> can't also declare ft2
>
I was under the impression that `ft1` would be permitted, since that's a=20
function declaration. Or was that ERROR comment a copy-and-paste bug?
The proposal should explicitly cover the "f2" case above; and if the intent=
=20
> is to support that case, then it should maybe not make such a big deal=20
> about "anonymous" types. The real issue here is just whether C++ should=
=20
> permit defining a new class type in the same declaration as various other=
=20
> kinds of entities (variables and typedefs yes, functions currently no). I=
=20
> think it would be a bad idea to support such declarations *only* when the=
=20
> new class type is anonymous.
>
I disagree. If a type is important enough to have a name, then it is=20
important enough to have its definition be on a separate line from a=20
function that returns it. After all, you would only name a type if you=20
intend to use that name in a place. And you'd only bother if that name were=
=20
being used independently of the function that returns it (ie: not an `auto`=
=20
variable deduced from the return of the function).
A declaration or definition should not be creating multiple named entities=
=20
like that.
Indeed, the whole point of this syntax is to *not* give the struct a=20
typename. That's part of the motivation: to not pollute the namespace with=
=20
needless typenames. If you needed to give it a typename, you'd just declare=
=20
the struct right before the function that returns it. It's not like this=20
syntax provides you a massive keystroke advantage.
The feature is for one-off bundles-of-types structs that don't need names.=
=20
It allows you to give names to multiple return values, so that you're not=
=20
locked into using tuples and such.
--=20
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 e=
mail 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/0f3fa3a5-ed6b-4c25-93d5-f96f7a380421%40isocpp.or=
g.
------=_Part_995_222150544.1482026187553
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Saturday, December 17, 2016 at 8:10:49 PM UTC-5, Arthur=
O'Dwyer wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D=
"ltr">On Sat, Dec 17, 2016 at 4:11 PM, Nicol Bolas <span dir=3D"ltr"><<a=
href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"Dk2L1hHaCg=
AJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:';retur=
n true;" onclick=3D"this.href=3D'javascript:';return true;">jmck...=
@gmail.com</a>></span> wrote:<br><div><div class=3D"gmail_quote"><blockq=
uote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-wi=
dth:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-=
left:1ex"><div dir=3D"ltr"><span>On Saturday, December 17, 2016 at 6:06:33 =
PM UTC-5, Arthur O'Dwyer wrote:<blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(20=
4,204,204);border-left-style:solid;padding-left:1ex"><div dir=3D"ltr"><bloc=
kquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-=
width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;paddin=
g-left:1ex"><br></blockquote><div style=3D"background-color:rgb(250,250,250=
);border:1px solid rgb(187,187,187);word-wrap:break-word"><code><div><span =
style=3D"color:rgb(0,0,136)">struct</span><span style=3D"color:rgb(0,0,0)">=
</span><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:r=
gb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">int</span><span style=
=3D"color:rgb(0,0,0)"> x</span><span style=3D"color:rgb(102,102,0)">,</span=
><span style=3D"color:rgb(0,0,0)"> y</span><span style=3D"color:rgb(102,102=
,0)">;</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:=
rgb(102,102,0)">}</span><span style=3D"color:rgb(0,0,0)"> f</span><span sty=
le=3D"color:rgb(102,102,0)">()</span><span style=3D"color:rgb(0,0,0)"> </sp=
an><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0,=
0,0)"> </span><span style=3D"color:rgb(102,102,0)">???</span><span style=3D=
"color:rgb(0,0,0)"> s</span><span style=3D"color:rgb(102,102,0)">;</span><s=
pan style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">r=
eturn</span><span style=3D"color:rgb(0,0,0)"> s</span><span style=3D"color:=
rgb(102,102,0)">;</span><span style=3D"color:rgb(0,0,0)"> </span><span styl=
e=3D"color:rgb(102,102,0)">}</span><span style=3D"color:rgb(0,0,0)"><br></s=
pan></div></code></div><div><br></div><div>where you additionally want-but-=
explicitly-do-not-<wbr>propose "decltype(return)" as the appropri=
ate syntax for "???".</div></div></blockquote></span><div><br>Not=
really. The idea being that you'd just do `return {};`. You would only=
need `decltype(return)` if you needed to declare a variable of the return =
type.<br><br>If you're using these anonymous structs as a way to do mul=
tiple return values without tuples, then you don't really need the retu=
rn type itself. So the proposal is genuinely useful independently of `declt=
ype(return)` to fetch the function's return type.<br></div></div></bloc=
kquote><div><br></div><div>True, I was too cartoonish there; but I stand by=
my assertion that I wouldn't want this feature (in fact I'd hope f=
or an opt-in compiler diagnostic on this feature) in my own codebases.</div=
></div></div></div></blockquote><div><br>I'm not exactly happy with the=
idea of promoting the creation of anonymous types myself. But I highly dou=
bt that there will ever be a compiler diagnostic on it. If for no other rea=
son than the fact that there will likely be standard library types that mak=
e use of it. You can't just add something to the language, then forbid =
any standard library components from ever making use of it.<br><br></div><b=
lockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;borde=
r-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div class=
=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px =
0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-l=
eft-style:solid;padding-left:1ex"><div dir=3D"ltr"><span><blockquote class=
=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;bo=
rder-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">=
<div dir=3D"ltr"><div>The second, more important =E2=80=94 possibly killer?=
=E2=80=94 problem is also illustrated by the above program: what does the =
following declaration(?) actually declare?</div><div><br></div><div style=
=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,187,187);wor=
d-wrap:break-word"><code><div><span style=3D"color:rgb(0,0,136)">template</=
span><span style=3D"color:rgb(102,102,0)"><</span><span style=3D"color:r=
gb(0,0,136)">class</span><span style=3D"color:rgb(0,0,0)"> T</span><span st=
yle=3D"color:rgb(102,102,0)">></span><span style=3D"color:rgb(0,0,0)"><b=
r></span><span style=3D"color:rgb(0,0,136)">struct</span><span style=3D"col=
or:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">{</span><span s=
tyle=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 </span><span style=3D"color:rgb=
(0,0,136)">int</span><span style=3D"color:rgb(0,0,0)"> s</span><span style=
=3D"color:rgb(102,102,0)">;</span><span style=3D"color:rgb(0,0,0)"><br></sp=
an><span style=3D"color:rgb(102,102,0)">}</span><span style=3D"color:rgb(0,=
0,0)"><br>tomorrow</span><span style=3D"color:rgb(102,102,0)">(</span><span=
style=3D"color:rgb(0,0,0)">T t</span><span style=3D"color:rgb(102,102,0)">=
)</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(1=
02,102,0)">{</span><span style=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 </spa=
n><span style=3D"color:rgb(0,0,136)">return</span><span style=3D"color:rgb(=
0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">{</span><span style=3D=
"color:rgb(0,0,136)">sizeof</span><span style=3D"color:rgb(0,0,0)"> t</span=
><span style=3D"color:rgb(102,102,0)">};</span><span style=3D"color:rgb(0,0=
,0)"><br></span><span style=3D"color:rgb(102,102,0)">}</span></div></code><=
/div><div><br></div><div>All the way until the first closing curly brace on=
line 4 =E2=80=94 i.e. all during the parsing of the struct body =E2=80=94 =
this <i>looks</i> like a class template definition.</div></div></blockquote=
></span><div><br>Does it? Because I'm <a href=3D"http://ideone.com/vRQu=
sf" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http=
://www.google.com/url?q\x3dhttp%3A%2F%2Fideone.com%2FvRQusf\x26sa\x3dD\x26s=
ntz\x3d1\x26usg\x3dAFQjCNEEYeOQOxkaIRcSAcAEFvi8as6DJg';return true;" on=
click=3D"this.href=3D'http://www.google.com/url?q\x3dhttp%3A%2F%2Fideon=
e.com%2FvRQusf\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEEYeOQOxkaIRcSAcAEFv=
i8as6DJg';return true;">fairly certain that class templates cannot be d=
eclared without a name</a>. That's not definitive; I wouldn't know =
where to start looking through the standard for this. But I'm pretty su=
re it can't happen; how would you instantiate one?<br></div></div></blo=
ckquote><div><br></div><div>You're right. But then maybe Matthew's =
proposal isn't adding as much consistency as I thought =E2=80=94 in tha=
t the current state of affairs isn't as consistent as I'd thought.=
=C2=A0 After some experimentation, I gather that today the situation is:</d=
iv><div><br></div><div>struct { } v1; =C2=A0// OK in C++98</div><div>struct=
S { } v2; =C2=A0// OK in C++98: declares both S and v2</div><div><div>stru=
ct { } f1() { return {}; } =C2=A0// ERROR in C++98</div><div>struct S { } f=
2() { return {}; } =C2=A0// ERROR in C++98</div><div></div></div><div><div>=
template<class T> struct { } vt1; =C2=A0// ERROR in C++14: a template=
must have a name, and can't also declare vt1</div></div><div><div>temp=
late<class T> struct S { } vt2; =C2=A0// ERROR in C++14: definition o=
f S<T> can't also declare vt2</div></div><div><div>template<cl=
ass T> struct { } ft1(); =C2=A0// ERROR in C++98: a template must have a=
name, and can't also declare ft1</div><div>template<class T> str=
uct S { } ft2(); =C2=A0// ERROR in C++98: definition of S<T> can'=
t also declare ft2</div></div><div><br></div><div>Matthew 's proposal m=
akes it this:</div><div><br></div><div><div>struct { } v1; =C2=A0// OK in C=
++98</div><div>struct S { } v2; =C2=A0// OK in C++98: declares both S and v=
2</div><div><div>struct { } f1() { return {}; } =C2=A0// OK in proposal</di=
v><div>struct S { } f2() { return {}; } =C2=A0// UNKNOWN in proposal: presu=
mably should declare both S and f2<br></div><div></div></div><div>template&=
lt;class T> struct { } vt1; =C2=A0// ERROR in C++14: a template must hav=
e a name, and can't also declare vt1</div><div>template<class T> =
struct S { } vt2; =C2=A0// ERROR in C++14: definition of S<T> can'=
;t also declare vt2</div><div><div>template<class T> struct { } ft1()=
; =C2=A0// ERROR in C++98: a template must have a name, and can't also =
declare ft1</div><div>template<class T> struct S { } ft2(); =C2=A0// =
ERROR in C++98: definition of S<T> can't also declare ft2</div></=
div></div></div></div></div></blockquote><div><br>I was under the impressio=
n that `ft1` would be permitted, since that's a function declaration. O=
r was that ERROR comment a copy-and-paste bug?<br><br></div><blockquote cla=
ss=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #=
ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div class=3D"gmail_quo=
te"><div><div></div></div><div>The proposal should explicitly cover the &qu=
ot;f2" case above; and if the intent is to support that case, then it =
should maybe not make such a big deal about "anonymous" types. Th=
e real issue here is just whether C++ should permit defining a new class ty=
pe in the same declaration as various other kinds of entities (variables an=
d typedefs yes, functions currently no). I think it would be a bad idea to =
support such declarations <i>only</i> when the new class type is anonymous.=
</div></div></div></div></blockquote><div><br>I disagree. If a type is impo=
rtant enough to have a name, then it is important enough to have its defini=
tion be on a separate line from a function that returns it. After all, you =
would only name a type if you intend to use that name in a place. And you&#=
39;d only bother if that name were being used independently of the function=
that returns it (ie: not an `auto` variable deduced from the return of the=
function).<br><br>A declaration or definition should not be creating multi=
ple named entities like that.<br><br>Indeed, the whole point of this syntax=
is to <i>not</i> give the struct a typename. That's part of the motiva=
tion: to not pollute the namespace with needless typenames. If you needed t=
o give it a typename, you'd just declare the struct right before the fu=
nction that returns it. It's not like this syntax provides you a massiv=
e keystroke advantage.<br><br>The feature is for one-off bundles-of-types s=
tructs that don't need names. It allows you to give names to multiple r=
eturn values, so that you're not locked into using tuples and such.<br>=
</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/0f3fa3a5-ed6b-4c25-93d5-f96f7a380421%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0f3fa3a5-ed6b-4c25-93d5-f96f7a380421=
%40isocpp.org</a>.<br />
------=_Part_995_222150544.1482026187553--
------=_Part_994_1006923881.1482026187552--
.
Author: "Arthur O'Dwyer" <arthur.j.odwyer@gmail.com>
Date: Mon, 19 Dec 2016 13:03:26 -0800
Raw View
--001a114b9e083d58670544094013
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Mon, Dec 19, 2016 at 12:04 PM, Matthew Woehlke <mwoehlke.floss@gmail.com=
>
wrote:
>
> Updated version attached. Thanks all for the feedback so far!
From your reply to my message:
>> template<class T> struct S { } vt2; // ERROR in C++14: definition of
S<T> can't also declare vt2
>
> Riiiight... particularly, `vt2` would have to be a template here, or
> else you'd somehow need an argument list.
Right, but I suspect you didn't notice that if you remove the body "{ }",
then the above becomes
template<class T> struct S vt2; // OK in C++14: declares variable
template vt2<T> of type S
So the specific grammatical quirk here is that variable templates behave
differently from variable non-templates. (Your proposal intends to
introduce the same quirk for function templates vis-a-vis function
non-templates, thus making functions behave more like variables.)
>> struct { int x, y; } f() { ??? s; return s; }
>> where you additionally want-but-explicitly-do-not-propose
>> "decltype(return)" as the appropriate syntax for "???".
>
> Um... it's *meant* to be explicitly proposed. Can you please clarify why
> you think I haven't done so, so I can fix it?
The current proposal says under "Future Directions": "A final consideration
is the extension of decltype(return) to allow use *within a function body*.
At the time of writing, we are not aware of a proposal to do so, although
the idea has been floated on numerous occasions. We would hope to see such
an addition, which can be *orthogonal to this proposal*, in the near
future."
From the updated proposal:
> The critical problem with this, which we wish specifically to address,
> is that a forward declaration of such a function is not possible.
Actually, you *can* forward-declare such a function; specifically what's
missing is a way to forward-declare such a function and its return type.
That is:
auto f();
is a valid forward declaration in C++14. (It was not valid in C++11 due to
the lack of a trailing return type.)
> This feature is not compatible with deduced return types at this time.
Agreed, but I don't think P0329 is relevant at all. I admit I've only
skimmed it, but I don't think P0329 adds the ability to deduce a type from
a braced-initializer-list as in your example. The actually relevant example
would be like this:
auto f(); // declare function with return type
int f() { return 0; } // ERROR in C++14: "ambiguating declaration" =E2=
=80=94
perhaps this should be proposed as OK?
int f(); // declare function with return type
auto f() { return 0; } // ERROR in C++14: "ambiguating declaration" =
=E2=80=94
perhaps this should be proposed as OK?
auto f(); // declare function with return type
auto f() { return 0; } // OK in C++14: define function without
redeclaring return type
int f(); // declare function with return type
decltype(return) f() { return 0; } // presumably OK: define function
without redeclaring return type
auto f(); // declare function without declaring return type
decltype(return) f() { return 0; } // presumably ERROR:
decltype(return) used before return type has been deduced
HTH,
=E2=80=93Arthur
--=20
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 e=
mail 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/CADvuK0%2B%3Dy%3Dn7YH_5fQvzSn4LM9rz%2BqwqwqdpZb0=
8X9o2Rp7Bdw%40mail.gmail.com.
--001a114b9e083d58670544094013
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Mon, Dec 19, 2016 at 12:04 PM, Matthew Woehlke <<a h=
ref=3D"mailto:mwoehlke.floss@gmail.com">mwoehlke.floss@gmail.com</a>> wr=
ote:<br>><br>> Updated version attached. Thanks all for the feedback =
so far!<br><br>From your reply to my message:<div><br></div><div><span styl=
e=3D"font-size:13px">>> template<class T> struct S { } vt2;=C2=
=A0 // ERROR in C++14: definition of S<T></span><span style=3D"font-s=
ize:13px">=C2=A0can't also declare vt2</span><br style=3D"font-size:13p=
x">><br style=3D"font-size:13px"><span style=3D"font-size:13px">> Rii=
iight... particularly, `vt2` would have to be a template here, or</span><br=
style=3D"font-size:13px"><span style=3D"font-size:13px">> else you'=
d somehow need an argument list.</span><br><br>Right, but I suspect you did=
n't notice that if you remove the body "{ }", then the above =
becomes</div><div><br></div><div><font face=3D"monospace, monospace">=C2=A0=
=C2=A0 template<class T> struct S vt2; =C2=A0// OK in C++14: declare=
s variable template vt2<T> of type S</font></div><div><br><span style=
=3D"font-size:13px">So the specific grammatical quirk here is that variable=
templates behave differently from variable non-templates. (Your proposal i=
ntends to introduce the same quirk for function templates vis-a-vis functio=
n non-templates, thus making functions behave more like variables.)</span><=
/div><div><span style=3D"font-size:13px"><br></span></div><div><span style=
=3D"font-size:13px">>> struct { int x, y; } f() { ??? s; return s; }<=
/span><br style=3D"font-size:13px">><span style=3D"font-size:13px">> =
where you additionally want-but-explicitly-do-not-</span><wbr style=3D"font=
-size:13px"><span style=3D"font-size:13px">propose</span><br style=3D"font-=
size:13px"><span style=3D"font-size:13px">>> "decltype(return)&q=
uot; as the appropriate syntax for "???".</span><br style=3D"font=
-size:13px">><br style=3D"font-size:13px"><span style=3D"font-size:13px"=
>> Um... it's *meant* to be explicitly proposed. Can you please clar=
ify why</span><br style=3D"font-size:13px"><span style=3D"font-size:13px">&=
gt; you think I haven't done so, so I can fix it?</span><br><br>The cur=
rent proposal says under "Future Directions": "A final consi=
deration is the extension of <font face=3D"monospace, monospace">decltype(r=
eturn)</font> to allow use <b>within a function body</b>. At the time of wr=
iting, we are not aware of a proposal to do so, although the idea has been =
floated on numerous occasions. We would hope to see such an addition, which=
can be <b>orthogonal to this proposal</b>, in the near future."</div>=
<div><br><br>From the updated proposal:<br> <br>> The critical problem w=
ith this, which we wish specifically to address,<div>> is that a forward=
declaration of such a function is not possible. <div><br></div><div>Actual=
ly, you <i>can</i> forward-declare such a function; specifically what's=
missing is a way to forward-declare such a function and its return type. T=
hat is:</div><div><br></div></div><div><font face=3D"monospace, monospace">=
=C2=A0 =C2=A0 auto f();</font></div><div><br></div><div>is a valid forward =
declaration in C++14. =C2=A0(It was not valid in C++11 due to the lack of a=
trailing return type.)</div><div><br></div><div>>=C2=A0This feature is =
not compatible with deduced return types at this time. </div><div><br></div=
><div>Agreed, but I don't think P0329 is relevant at all. I admit I'=
;ve only skimmed it, but I don't think P0329 adds the ability to deduce=
a type from a braced-initializer-list as in your example. The actually rel=
evant example would be like this:</div><div><br></div><div><font face=3D"mo=
nospace, monospace">=C2=A0 =C2=A0 auto f(); =C2=A0// declare function with =
return type<br></font></div><div><div><div><font face=3D"monospace, monospa=
ce">=C2=A0 =C2=A0 int f() { return 0; } =C2=A0// ERROR in C++14: "ambi=
guating declaration" =E2=80=94 perhaps this should be proposed as OK?<=
/font></div><div><font face=3D"monospace, monospace"><br></font></div></div=
><div><div><font face=3D"monospace, monospace">=C2=A0 =C2=A0 int f(); =C2=
=A0// declare function with return type</font></div><div><font face=3D"mono=
space, monospace">=C2=A0 =C2=A0 auto f() { return 0; } =C2=A0// ERROR in C+=
+14: "ambiguating declaration" =E2=80=94 perhaps this should be p=
roposed as OK?</font></div><div><font face=3D"monospace, monospace"><br></f=
ont></div></div><div><font face=3D"monospace, monospace">=C2=A0 =C2=A0 auto=
f(); =C2=A0// declare function with return type</font></div><div><font fac=
e=3D"monospace, monospace">=C2=A0 =C2=A0 auto f() { return 0; } =C2=A0// OK=
in C++14: define function without redeclaring return type</font></div></di=
v><div><font face=3D"monospace, monospace"><br></font></div><div><div><font=
face=3D"monospace, monospace">=C2=A0 =C2=A0 int f(); =C2=A0// declare func=
tion with return type</font></div><div><font face=3D"monospace, monospace">=
=C2=A0 =C2=A0 decltype(return) f() { return 0; } =C2=A0// presumably OK: de=
fine function without redeclaring return type</font></div><div><font face=
=3D"monospace, monospace"><br></font></div><div><div></div></div><div><font=
face=3D"monospace, monospace">=C2=A0 =C2=A0 auto f(); =C2=A0// declare fun=
ction without declaring return type</font></div><div><font face=3D"monospac=
e, monospace">=C2=A0 =C2=A0 decltype(return) f() { return 0; } =C2=A0// pre=
sumably ERROR: decltype(return) used before return type has been deduced</f=
ont></div><div><br></div></div><div><br></div><div>HTH,</div><div>=E2=80=93=
Arthur</div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/CADvuK0%2B%3Dy%3Dn7YH_5fQvzSn4LM9rz%2=
BqwqwqdpZb08X9o2Rp7Bdw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoo=
ter">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CADvuK0%2=
B%3Dy%3Dn7YH_5fQvzSn4LM9rz%2BqwqwqdpZb08X9o2Rp7Bdw%40mail.gmail.com</a>.<br=
/>
--001a114b9e083d58670544094013--
.