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


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

Why this behaviour for literal types?

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.albasani.net!.POSTED!not-for-mail
From Andrzej Krzemieński<akrzemi1@gmail.com>
Newsgroups comp.std.c++
Subject Why this behaviour for literal types?
Date Wed, 14 Mar 2012 13:33:54 -0700 (PDT)
Organization http://groups.google.com
Lines 31
Sender std-cpp-request@vandevoorde.com
Approved stephen.clamage@oracle.com
Message-ID <1615055.1458.1331755052471.JavaMail.geo-discussion-forums@vbgx21> (permalink)
NNTP-Posting-Host Ei0J1tUw+8X5MsxW7WRn98eyJoSRyJpUdqWP+ftcpeY=
Content-Type text/plain; charset=ISO-8859-1
X-Trace news.albasani.net fhIyyjmF2rf/7K03IrWn8b+SdGBAwfF2+70JbNdw/OyV7eU6h26gUQRw9/vcpu8iUBIvSfl8m7hwgYjkN1Kf0g==
X-Complaints-To abuse@albasani.net
NNTP-Posting-Date Wed, 14 Mar 2012 20:33:56 +0000 (UTC)
X-Mailer Perl5 Mail::Internet v2.05
X-Submission-Address std-cpp-submit@vandevoorde.com
Cancel-Lock sha1:SOTguwE74RCiiCNi77rHA8ShlWY=
X-Original-Date Wed, 14 Mar 2012 12:57:32 -0700 (PDT)
Xref csiph.com comp.std.c++:443

Show key headers only | View raw


Hi,
This is my literal type:

   struct C
   {
     double m;
     constexpr C( double m ) : m{m} {};
     constexpr double get() const { return m; };
   };

Therefore the following code works:

   constexpr C c = C{5.};
   constexpr double k = c.get();

But the following does not:

   const C cc = C{5.};  // but not constexpr
   constexpr double kk = cc.get();

Why is this so? Object cc is subject to const initialization anyway. It is possible to make it work only by a seemingly irrelevant change in declaration (add constexpr). What was the reason for disallowing this "implicit generation of compile-time constants"?

Regards,
&rzej


-- 
[ 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 | NextNext 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