[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] static constexpr
From: |
Greg Chicares |
Subject: |
Re: [lmi] static constexpr |
Date: |
Thu, 17 Jun 2021 22:48:03 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 |
On 6/17/21 11:24 AM, Vadim Zeitlin wrote:
> On Wed, 16 Jun 2021 22:20:45 +0000 Greg Chicares <gchicares@sbcglobal.net>
> wrote:
[...]
> GC> https://isocpp.org/blog/2013/12/constexpr
> GC> | constexpr guarantees compile-time evaluation *is possible if*
> GC> | operating on a compile-time value, and that compile-time
> GC> | evaluation *will happen if* a compile-time result is needed.
Postulate:
That plain and simple statement quoted from isocpp.org/blog would have
been withdrawn by now if it were not the universal consensus, so it
can be treated as though it were actually normative in this case,
as nothing in the Standard seems to decide this issue definitively.
Of course that's not normative, but I'll take it as authoritative anyway.
> GC> so in the lmi code we're discussing:
> GC> constexpr T zero {};
> GC> we're guaranteed that compile-time evaluation is possible
> GC> (because it doesn't depend on any non-compile-time value),
> GC> but are we guaranteed that compile-time evaluation will
> GC> occur?
> GC>
> GC> Is the answer that this:
> GC> constexpr T zero {};
> GC> is a "constexpr context"? so that the "*will happen if*" clause
> GC> above necessarily comes into effect? and so that, no matter what
> GC> initializer follows
> GC> constexpr T zero ...
> GC> , if it compiles, then the initialization is guaranteed to
> GC> occur at compile time? Or, more properly speaking, that the
> GC> *initializing value* must be computed at compile time, which
> GC> would be enough to satisfy me?
>
> Again, I think so, but I can't prove it right now.
Rethinking this a day later, I believe I did prove that, above,
relying on the Postulate above: i.e., if we have any definition
T t {whatever};
and we want to ensure that the initializing value is computed at
compile time, then it suffices to prepend 'constexpr':
constexpr T t {whatever};
Effects:
- If there's no constexpr ctor, we the compiler must diagnose that.
- Prepending 'constexpr' makes this definition a "constexpr context",
so the initializing value is guaranteed to be computed at compile time.
Relying on that reasoning, I'm making the change you recommended.
- Re: [lmi] [lmi-commits] master c01b9b0 02/22: Improve concinnity, Vadim Zeitlin, 2021/06/07
- Re: [lmi] [lmi-commits] master c01b9b0 02/22: Improve concinnity, Greg Chicares, 2021/06/15
- Re: [lmi] [lmi-commits] master c01b9b0 02/22: Improve concinnity, Vadim Zeitlin, 2021/06/15
- Re: [lmi] [lmi-commits] master c01b9b0 02/22: Improve concinnity, Greg Chicares, 2021/06/15
- [lmi] static constexpr [Was: master c01b9b0 02/22: Improve concinnity], Greg Chicares, 2021/06/16
- Re: [lmi] static constexpr, Vadim Zeitlin, 2021/06/16
- Re: [lmi] static constexpr, Greg Chicares, 2021/06/16
- Re: [lmi] static constexpr, Vadim Zeitlin, 2021/06/17
- Re: [lmi] static constexpr,
Greg Chicares <=