This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[wwwdocs] Add a note about in-class initialization of static data member
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Jonathan Wakely <jwakely at redhat dot com>
- Date: Thu, 11 Feb 2016 15:20:00 +0100
- Subject: [wwwdocs] Add a note about in-class initialization of static data member
- Authentication-results: sourceware.org; auth=none
Does this look ok?
Index: porting_to.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-6/porting_to.html,v
retrieving revision 1.9
diff -u -r1.9 porting_to.html
--- porting_to.html 10 Feb 2016 17:21:54 -0000 1.9
+++ porting_to.html 11 Feb 2016 14:18:59 -0000
@@ -269,6 +269,25 @@
to port the code to use C++11's <code>std::unique_ptr</code> instead.
</p>
+<h3>'constexpr' needed for in-class initialization of static data member</h3>
+
+<p>
+Since C++11, the <code>constexpr</code> keyword is needed when initializing
+a non-integral static data member in a class. Thus the following program is
+accepted in C++03 (albeit with a <tt>-Wpedantic</tt> warning):
+</p>
+
+<pre><code>
+struct X {
+ const static double i = 10;
+};
+</pre></code>
+
+<p>
+While in C++11, the program above is rejected with an error. The fix is to
+use <code>constexpr</code> instead of <code>const</code>.
+</p>
+
<h2>-Wmisleading-indentation</h2>
<p>
A new warning <code>-Wmisleading-indentation</code> was added
Marek