Discussion:
[std-proposals] Are parameters of constexpr! functions necessarily themselves constant expressions?
Brian Bi
2018-11-04 20:14:58 UTC
Permalink
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+***@isocpp.org.
To post to this group, send email to std-***@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.
Nicolas Lesser
2018-11-04 20:27:09 UTC
Permalink
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 :)
Post by Brian Bi
functions declared with the constexpr! specifier, which forces all
invocations to be constant expressions. I wonder whether it might make
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
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+***@isocpp.org.
To post to this group, send email to std-***@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.
Loading...