This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [wwwdocs] Add a note about in-class initialization of static data member
- From: Marek Polacek <polacek at redhat dot com>
- To: Martin Sebor <msebor at gmail dot com>
- Cc: Jonathan Wakely <jwakely at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 11 Feb 2016 18:59:33 +0100
- Subject: Re: [wwwdocs] Add a note about in-class initialization of static data member
- Authentication-results: sourceware.org; auth=none
- References: <20160211142000 dot GB3163 at redhat dot com> <20160211152613 dot GR8441 at redhat dot com> <20160211163958 dot GC3163 at redhat dot com> <56BCC03F dot 5000904 at gmail dot com>
On Thu, Feb 11, 2016 at 10:09:19AM -0700, Martin Sebor wrote:
> It''s interesting that when the example is modified to use a double
> initializer it is rejected with a hard error even in C++ 03 mode
> when -Wpedantic (but not -Werror) is used. That seems like a bug.
> If it isn't, it might be worth mentioning the constraint that the
> initializer must be a integer in the text above.
>
> struct X {
> const static double i = 3.14;
> };
>
> error: floating-point literal cannot appear in a constant-expression
> const static double i = 3.14;
> ^~~~
Hm, indeed; I hadn't notice that. Dunno if is a bug (clang++ accepts this
with a warning). I've added ", provided the initializer is an integer",
that should be enough.
> >+<h3>Stricter flexible array member rules</h3>
> >+
> >+<p>
> >+As of this release, the C++ compiler is now more strict about flexible array
> >+member rules. As a consequence, the following code is no longer accepted:
>
> In light of bug 69550 I think it might be useful to also mention
> (or show an example) that structs with a flexible array as the
> only member are rejected as well.
Somehow I knew you'd have something to add here ;). How about this then?
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 17:58:43 -0000
@@ -269,6 +269,53 @@
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. As a GNU extension, the following
+program is accepted in C++03 (albeit with a <tt>-Wpedantic</tt> warning),
+provided the initializer is an integer:
+</p>
+
+<pre><code>
+struct X {
+ const static double i = 10;
+};
+</pre></code>
+
+<p>
+The C++11 standard supports that in-class initialization using
+<code>constexpr</code> instead, so the GNU extension is no longer supported for
+C++11 or later. Programs relying on the extension will be rejected with an
+error. The fix is to use <code>constexpr</code> instead of <code>const</code>.
+</p>
+
+<h3>Stricter flexible array member rules</h3>
+
+<p>
+As of this release, the C++ compiler is now more strict about flexible array
+member rules. As a consequence, the following code is no longer accepted:
+</p>
+
+<pre><code>
+union U {
+ int i;
+ char a[];
+};
+</pre></code>
+
+<p>
+Furthermore, the C++ compiler now rejects structures with a flexible array
+member as the only member:
+</p>
+
+<pre><code>
+struct S {
+ char a[];
+};
+</pre></code>
+
<h2>-Wmisleading-indentation</h2>
<p>
A new warning <code>-Wmisleading-indentation</code> was added
Marek