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: =?ISO-8859-2?Q?Andrzej_Krzemie=F1ski?= 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= 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 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 ]