Topic: Defect? Both gcc and clang instantiate
Author: Jens Maurer <Jens.Maurer@gmx.net>
Date: Tue, 26 Jun 2018 11:38:35 +0200
Raw View
On 06/26/2018 09:56 AM, Boris Rasin wrote:
> // Both clang and gcc (in C++17 mode) complain about "invalid use of incomplete type".
> // But if all A's constructors are "=deleted", both clang and gcc compile successfully.
> // They don't need ANY constructor, yet try to instantiate them all.
> // Is this somehow mandated by the standard, or simply a bug in both clang and gcc?
>
> template <typename T>
> struct A
> {
> using type = typename T::type;
> A(type);
> };
>
> struct B;
>
> A<B> func();
> A<B> func2() { return func(); }
This has nothing to do with constructors.
The point is that the definition of func2 requires
its return type to be a complete type ([dcl.fct] 11.3.5 p12),
which triggers instantiation of A<B>.
Instantiation of the class template A causes instantiation
of the typedef, which requires "B" to be a complete type.
Jens
--
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/5B32099B.6030407%40gmx.net.
.
Author: Boris Rasin <rasin.boris@gmail.com>
Date: Tue, 26 Jun 2018 03:30:57 -0700 (PDT)
Raw View
------=_Part_41839_567459064.1530009057301
Content-Type: multipart/alternative;
boundary="----=_Part_41840_2045471883.1530009057302"
------=_Part_41840_2045471883.1530009057302
Content-Type: text/plain; charset="UTF-8"
On Tuesday, June 26, 2018 at 12:38:39 PM UTC+3, Jens Maurer wrote:
>
> This has nothing to do with constructors.
>
> The point is that the definition of func2 requires
> its return type to be a complete type ([dcl.fct] 11.3.5 p12),
> which triggers instantiation of A<B>.
>
> Instantiation of the class template A causes instantiation
> of the typedef, which requires "B" to be a complete type.
>
> Jens
>
My apologies, I posted the wrong version of the code.
Here is the correct version.
The issue I described still stands: if you comment out constructor "
A(type<>);" than code will compile.
template <typename T>
struct A
{
template <typenameX = T>
using type = typename X::type;
A(type<>);
};
struct B;
A<B> func();
A<B> func2() { returnfunc(); }
--
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/6aed481d-0d12-4321-b768-dfd146c2148d%40isocpp.org.
------=_Part_41840_2045471883.1530009057302
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, June 26, 2018 at 12:38:39 PM UTC+3, Jens Maure=
r wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0=
..8ex;border-left: 1px #ccc solid;padding-left: 1ex;">This has nothing to do=
with constructors.
<br>
<br>The point is that the definition of func2 requires
<br>its return type to be a complete type ([dcl.fct] 11.3.5 p12),
<br>which triggers instantiation of A<B>.
<br>
<br>Instantiation of the class template A causes instantiation
<br>of the typedef, which requires "B" to be a complete type.
<br>
<br>Jens
<br></blockquote><div><br></div><div>My apologies, I posted the wrong versi=
on of the code.</div><div>Here is the correct version.</div><div> The issue=
I described still stands: if you comment out constructor "<span style=
=3D"color: rgb(0, 0, 0);">A(type<>);</span>" than code will comp=
ile.<br></div><div><br></div><div><div style=3D"caret-color: rgb(0, 0, 0); =
color: rgb(0, 0, 0); font-family: -webkit-standard; font-style: normal; fon=
t-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphan=
s: auto; text-align: start; text-indent: 0px; text-transform: none; white-s=
pace: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: au=
to; -webkit-text-stroke-width: 0px; text-decoration: none; background-color=
: rgb(255, 255, 254);"><div><span style=3D"color: rgb(0, 0, 255);">template=
</span><span style=3D"color: rgb(0, 0, 0);"><</span><span style=3D"colo=
r: rgb(0, 0, 255);">typename</span><span style=3D"color: rgb(0, 0, 0);"> T&=
gt;</span></div><div><span style=3D"color: rgb(0, 0, 255);">struct</span><s=
pan style=3D"color: rgb(0, 0, 0);"> A</span></div><div><span style=3D"color=
: rgb(0, 0, 0);">{</span></div><div><span style=3D"color: rgb(0, 0, 0);"></=
span><span style=3D"color: rgb(0, 0, 255);">=C2=A0 template </span><span st=
yle=3D"color: rgb(0, 0, 0);"><</span><span style=3D"color: rgb(0, 0, 255=
);">typename</span><span style=3D"color: rgb(0, 0, 0);">X =3D T></span><=
/div><div><span style=3D"color: rgb(0, 0, 0);"></span><span style=3D"color:=
rgb(0, 0, 255);">=C2=A0 using </span><span style=3D"color: rgb(0, 0, 0);">=
type =3D<span class=3D"Apple-converted-space">=C2=A0</span></span><span sty=
le=3D"color: rgb(0, 0, 255);">typename</span><span style=3D"color: rgb(0, 0=
, 0);"> X::type;</span></div><br><div><span style=3D"color: rgb(0, 0, 0);">=
=C2=A0 A(type<>);</span></div><div><span style=3D"color: rgb(0, 0, 0)=
;">};</span></div><br><div><span style=3D"color: rgb(0, 0, 255);">struct </=
span><span style=3D"color: rgb(0, 0, 0);">B;</span></div><br><div><span sty=
le=3D"color: rgb(0, 0, 0);">A<B> func();</span></div><div><span style=
=3D"color: rgb(0, 0, 0);">A<B> func2() {<span class=3D"Apple-converte=
d-space">=C2=A0</span></span><span style=3D"color: rgb(0, 0, 255);">return<=
/span><span style=3D"color: rgb(0, 0, 0);">func(); }</span></div><br></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/6aed481d-0d12-4321-b768-dfd146c2148d%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6aed481d-0d12-4321-b768-dfd146c2148d=
%40isocpp.org</a>.<br />
------=_Part_41840_2045471883.1530009057302--
------=_Part_41839_567459064.1530009057301--
.
Author: Boris Rasin <rasin.boris@gmail.com>
Date: Tue, 26 Jun 2018 10:38:30 -0700 (PDT)
Raw View
------=_Part_15983_1696829284.1530034710247
Content-Type: multipart/alternative;
boundary="----=_Part_15984_1203660026.1530034710247"
------=_Part_15984_1203660026.1530034710247
Content-Type: text/plain; charset="UTF-8"
I think I got it. Per [temp.inst], all class template member function
declarations are instantiated when class template is instantiated, it's
only the definitions that are instantiated on first use. So in the
following example func1 causes an error, while func2 is fine. Looks like
clang and gcc are correct here.
<https://timsong-cpp.github.io/cppwp/n4659/temp.inst>
struct B;
template <typename T>
struct A
{
template <typename X = T>
using type = typename X::type;
void func1(type<>);
void func2() { type<> t; }
};
void test()
{
A<B> a;
}
--
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/27a351d7-05a0-48e3-92e8-1d70fa2c4f25%40isocpp.org.
------=_Part_15984_1203660026.1530034710247
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>I think I got it. Per <a class=3D"abbr_ref" href=3D"h=
ttps://timsong-cpp.github.io/cppwp/n4659/temp.inst">[temp.inst]<span style=
=3D"color: rgb(0, 0, 0);">, all class template member function declarations=
are instantiated when class template is instantiated, it's only the de=
finitions that are instantiated on first use. So in the following example f=
unc1 causes an error, while func2 is fine. Looks like clang and gcc are cor=
rect here.<br></span></a></div><div><div><br></div><div>struct B;<br><br>te=
mplate <typename T><br>struct A<br>{<br>=C2=A0=C2=A0=C2=A0 template &=
lt;typename X =3D T><br>=C2=A0=C2=A0=C2=A0 using type =3D typename X::ty=
pe;<br><br>=C2=A0=C2=A0=C2=A0 void func1(type<>);<br>=C2=A0=C2=A0=C2=
=A0 void func2() { type<> t; }<br>};<br><br>void test()<br>{<br>=C2=
=A0=C2=A0=C2=A0 A<B> a;<br>}<br><br></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/27a351d7-05a0-48e3-92e8-1d70fa2c4f25%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/27a351d7-05a0-48e3-92e8-1d70fa2c4f25=
%40isocpp.org</a>.<br />
------=_Part_15984_1203660026.1530034710247--
------=_Part_15983_1696829284.1530034710247--
.