Thanks Diego,

Here's a new version of the patch with fixes for your comments. I'll
submit it in a couple hours unless I hear objections.

On Fri, Oct 28, 2011 at 7:57 AM, Diego Novillo <dnovi...@google.com> wrote:
> On Thu, Oct 27, 2011 at 09:27,  <jyass...@google.com> wrote:
>> Reviewers: Diego Novillo,
>>
>> Message:
>> This patch is intended for the google/gcc-4_6 branch. Tested with make
>> check-c++ on ubuntu x86-64.
>>
>> Should this go to gcc-patches@gcc.gnu.org too, or just the internal
>> list?
>
> As you prefer.  Strictly speaking, yes, in case other C++ maintainers
> have feedback on your patch.  But given that it is a patch that you
> intend to keep in a google release only, then it does not really
> matter all that much.
>
>>
>> Description:
This patch allows us to migrate to C++11 more incrementally, since we can leave
the static const float initializations in place, flip the switch, and then
change them to use constexpr.

We should NOT forward-port this to any gcc-4.7 branches.


gcc/cp/ChangeLog.google-4_6
2011-10-28  Jeffrey Yasskin  <jyass...@google.com>

        google ref 5514746; backport of r179121

        Modified locally to only block static const literals in -pedantic
        mode.

        2011-09-23  Paolo Carlini  <paolo.carl...@oracle.com>

                * decl.c (check_static_variable_definition): Allow in-class
                initialization of static data member of non-integral type in
                permissive mode.


gcc/testsuite/ChangeLog.google-4_6
2011-10-28  Jeffrey Yasskin  <jyass...@google.com>

        google ref 5514746; backport of r179121

        Modified locally to only block static const literals in -pedantic
        mode.

        * g++.dg/cpp0x/constexpr-static8_nonpedantic.C: New.

        2011-09-23  Paolo Carlini  <paolo.carl...@oracle.com>

                * g++.dg/cpp0x/constexpr-static8.C: New.
>>
>> You can review this at http://codereview.appspot.com/5306071/
>>
>> Affected files:
>>  M     gcc/cp/ChangeLog.google-4_6
>>  M     gcc/cp/decl.c
>>  M     gcc/testsuite/ChangeLog.google-4_6
>>  A     gcc/testsuite/g++.dg/cpp0x/constexpr-static8.C
>>  A     gcc/testsuite/g++.dg/cpp0x/constexpr-static8_nonpedantic.C
>>
...
>> Index: gcc/cp/decl.c
>> ===================================================================
>> --- gcc/cp/decl.c       (revision 180546)
>> +++ gcc/cp/decl.c       (working copy)
>> @@ -7508,8 +7508,12 @@ check_static_variable_definition (tree decl, tree
>>   else if (cxx_dialect >= cxx0x && !INTEGRAL_OR_ENUMERATION_TYPE_P (type))
>>     {
>>       if (literal_type_p (type))
>> -       error ("%<constexpr%> needed for in-class initialization of static "
>> -              "data member %q#D of non-integral type", decl);
>> +        {
>> +          pedwarn (input_location, OPT_pedantic,
>> +                   "%<constexpr%> needed for in-class initialization of "
>> +                   "static data member %q#D of non-integral type", decl);
>> +          return 0;
>> +        }
>
> Add a 'FIXME google' here?  Describe why this is different than
> upstream.  Helps with merge conflicts.

Done.

> OK with those changes.
>
>
> Diego.
>
Index: gcc/testsuite/g++.dg/cpp0x/constexpr-static8.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/constexpr-static8.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/constexpr-static8.C	(revision 0)
@@ -0,0 +1,7 @@
+// PR c++/50258
+// { dg-options "-std=c++0x -pedantic" }
+
+struct Foo {
+  static const double d = 3.14; // { dg-warning "constexpr" }
+};
+const double Foo::d;
Index: gcc/testsuite/g++.dg/cpp0x/constexpr-static8_nonpedantic.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/constexpr-static8_nonpedantic.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/constexpr-static8_nonpedantic.C	(revision 0)
@@ -0,0 +1,7 @@
+// PR c++/50258
+// { dg-options "-std=c++0x" }
+
+struct Foo {
+  static const double d = 3.14; // no warning
+};
+const double Foo::d;
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 180546)
+++ gcc/cp/decl.c	(working copy)
@@ -7508,8 +7508,18 @@
   else if (cxx_dialect >= cxx0x && !INTEGRAL_OR_ENUMERATION_TYPE_P (type))
     {
       if (literal_type_p (type))
-	error ("%<constexpr%> needed for in-class initialization of static "
-	       "data member %q#D of non-integral type", decl);
+        {
+          /* FIXME google: This local modification allows us to
+             transition from C++98 to C++11 without moving static
+             const floats out of the class during the transition.  It
+             should not be forward-ported to a 4.7 branch, since by
+             then we should be able to just fix the code to use
+             constexpr.  */
+          pedwarn (input_location, OPT_pedantic,
+                   "%<constexpr%> needed for in-class initialization of "
+                   "static data member %q#D of non-integral type", decl);
+          return 0;
+        }
       else
 	error ("in-class initialization of static data member %q#D of "
 	       "non-literal type", decl);

Reply via email to