From -5709062823458998362
X-Google-Thread: f78e5,93bf85197fa41c1e,start
X-Google-NewGroupId: yes
X-Google-Attributes: gid7894ca11fe,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Received: by 10.68.227.166 with SMTP id sb6mr3732620pbc.4.1331757236597;
        Wed, 14 Mar 2012 13:33:56 -0700 (PDT)
MIME-Version: 1.0
Path: h9ni26348pbe.0!nntp.google.com!news1.google.com!news.glorb.com!feeder.erje.net!news.albasani.net!.POSTED!not-for-mail
From: =?ISO-8859-2?Q?Andrzej_Krzemie=F1ski?=<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>
NNTP-Posting-Host: Ei0J1tUw+8X5MsxW7WRn98eyJoSRyJpUdqWP+ftcpeY=
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)
Content-Type: text/plain; charset=ISO-8859-1

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                      ]


