Topic: Are parameters of constexpr! functions


Author: Nicolas Lesser <blitzrakete@gmail.com>
Date: Sun, 4 Nov 2018 21:27:09 +0100
Raw View
--00000000000077f8030579dc98a6
Content-Type: text/plain; charset="UTF-8"

Hey I had the exact same question several months ago! :)

So I asked around and as it turns out this is very problematic for the
compiler. When evaluating functions as constant expressions, the compiler
switches to like an "interpreter" mode where no template instantiations can
be performed. Because of templates, invoking the function with different
parameters can get different results.

One related problem with this is that this would mean that the function for
all intents and purposes just like a template is: You can possibly get
different functions from a single function.

constexpr parameters also suffer from this problem.
So, this was an explicit design decision AFAIK.

P.S. it's consteval now :)

On Sun, Nov 4, 2018, 9:15 PM Brian Bi <bbi5291@gmail.com wrote:

> P1073R1 <http://wg21.link/p1073r1> introduces immediate functions:
> functions declared with the constexpr! specifier, which forces all
> invocations to be constant expressions. I wonder whether it might make
> sense to allow the following type of code:
>
> template <int> struct Foo {};
> constexpr! void bar(int x) { Foo<x> foo; }
>
> --
> *Brian Bi*
>
> --
> 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/CAMmfjbOT8toNhvzWc9NoCrb0G3DYOzc%2BRZ9yZZrd6jtJDs1G%3DQ%40mail.gmail.com
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAMmfjbOT8toNhvzWc9NoCrb0G3DYOzc%2BRZ9yZZrd6jtJDs1G%3DQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

--
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/CALmDwq2q6oemTaShORseL-iMA4WMhT7xMDZ3UnduG36PK8K6-g%40mail.gmail.com.

--00000000000077f8030579dc98a6
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto"><div>Hey I had the exact same question several months ago=
! :)</div><div dir=3D"auto"><br></div><div dir=3D"auto">So I asked around a=
nd as it turns out this is very problematic for the compiler. When evaluati=
ng functions as constant expressions, the compiler switches to like an &quo=
t;interpreter&quot; mode where no template instantiations can be performed.=
 Because of templates, invoking the function with different parameters can =
get different results.</div><div dir=3D"auto"><br></div><div dir=3D"auto">O=
ne related problem with this is that this would mean that the function for =
all intents and purposes just like a template is: You can possibly get diff=
erent functions from a single function.</div><div dir=3D"auto"><br></div><d=
iv dir=3D"auto">constexpr parameters also suffer from this problem.</div><d=
iv dir=3D"auto">So, this was an explicit design decision AFAIK.</div><div d=
ir=3D"auto"><br></div><div dir=3D"auto">P.S. it&#39;s consteval now :)<br><=
br><div class=3D"gmail_quote" dir=3D"auto"><div dir=3D"ltr">On Sun, Nov 4, =
2018, 9:15 PM Brian Bi &lt;<a href=3D"mailto:bbi5291@gmail.com">bbi5291@gma=
il.com</a> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margi=
n:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">=
<div><a href=3D"http://wg21.link/p1073r1" target=3D"_blank" rel=3D"noreferr=
er">P1073R1</a> introduces immediate functions: functions declared with the=
 <span style=3D"font-family:monospace,monospace">constexpr!</span> specifie=
r, which forces all invocations to be constant expressions. I wonder whethe=
r it might make sense to allow the following type of code:<span style=3D"fo=
nt-family:monospace,monospace"></span><br></div><div><span style=3D"font-fa=
mily:monospace,monospace"></span><span style=3D"font-family:monospace,monos=
pace"></span><br><span style=3D"font-family:monospace,monospace"></span><sp=
an style=3D"font-family:monospace,monospace">template &lt;int&gt; struct Fo=
o {};</span><span style=3D"font-family:monospace,monospace"></span><span st=
yle=3D"font-family:monospace,monospace"><br>constexpr! void bar(int x) { Fo=
o&lt;x&gt; foo; }</span></div><div><br></div><div>-- <br></div><div><div di=
r=3D"ltr" class=3D"m_8552479098245877798gmail_signature" data-smartmail=3D"=
gmail_signature"><div dir=3D"ltr"><div><div dir=3D"ltr"><font color=3D"#c0c=
0c0"><i>Brian Bi</i></font><br><div></div><div></div><div></div></div></div=
></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&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" target=3D"_=
blank" rel=3D"noreferrer">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank" rel=3D"noreferrer">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/CAMmfjbOT8toNhvzWc9NoCrb0G3DYOzc%2BRZ=
9yZZrd6jtJDs1G%3DQ%40mail.gmail.com?utm_medium=3Demail&amp;utm_source=3Dfoo=
ter" target=3D"_blank" rel=3D"noreferrer">https://groups.google.com/a/isocp=
p.org/d/msgid/std-proposals/CAMmfjbOT8toNhvzWc9NoCrb0G3DYOzc%2BRZ9yZZrd6jtJ=
Ds1G%3DQ%40mail.gmail.com</a>.<br>
</blockquote></div></div></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/CALmDwq2q6oemTaShORseL-iMA4WMhT7xMDZ3=
UnduG36PK8K6-g%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALmDwq2q6oemTaSh=
ORseL-iMA4WMhT7xMDZ3UnduG36PK8K6-g%40mail.gmail.com</a>.<br />

--00000000000077f8030579dc98a6--

.