Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #448

Re: Why this behaviour for literal types?

From Daniel Krügler<daniel.kruegler@googlemail.com>
Newsgroups comp.std.c++
Subject Re: Why this behaviour for literal types?
Date 2012-03-18 11:31 -0700
Organization A noiseless patient Spider
Message-ID <jk2k8o$uut$1@dont-email.me> (permalink)
References <1615055.1458.1331755052471.JavaMail.geo-discussion-forums@vbgx21> <jjr2a2$bdt$1@dont-email.me> <10974227.651.1331889037040.JavaMail.geo-discussion-forums@vbbed8>

Show all headers | View raw


Am 17.03.2012 08:53, schrieb Andrzej Krzemieński:
>  I am now trying to understand the conditions in 5.19 P 2 and it
>  appears to me that the following initialization should work fine:
>
>    struct C // C is same as above
>    {
>      double m;
>      constexpr C( double m ) : m{m} {};
>      constexpr double get() const { return m; };
>    };
>
>    C&&   rr = C{5.};  // no const!
>
>    constexpr double kk = rr.get();
>
>  Reference rr is not even a reference to const. In the last line the
>  initializing expression involves an lvalue-to-rvalue conversion (or
>  not?) but I am protected by the third "unless" sub-bullet because
>  reference rr is a glvalue of literal type that refers to a
>  non-volatile temporary object whose lifetime has not ended,
>  initialized with a constant expression.
>
>  Am I missing something obvious here, or should the above example just
>  compile fine?

I don't think that you are missing something. This looks like a clear
defect in the wording, because it is also clear that it is not intended
to be well-formed. A similar problem applies to

const C&  lr = C{5.};

because any following code could *legally* apply const_cast<C&>(lr)
here, because the referenced value is *not* constant.

I'm forwarding your example (and the other one based on an
lvalue-reference) to the core language group.

Thanks&  Greetings from Bremen,

Daniel Krügler




-- 
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | NextPrevious in thread | Find similar


Thread

Why this behaviour for literal types? Andrzej Krzemieński<akrzemi1@gmail.com> - 2012-03-14 13:33 -0700
  Re: Why this behaviour for literal types? Daniel Krügler<daniel.kruegler@googlemail.com> - 2012-03-15 11:33 -0700
    Re: Why this behaviour for literal types? Andrzej Krzemieński <akrzemi1@gmail.com> - 2012-03-17 00:53 -0700
      Re: Why this behaviour for literal types? Jason McKesson<jmckesson@gmail.com> - 2012-03-17 07:50 -0700
      Re: Why this behaviour for literal types? Daniel Krügler<daniel.kruegler@googlemail.com> - 2012-03-18 11:31 -0700

csiph-web