[cfe-commits] r140820 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/CXX/class/class.static/class.static.data/p3.cpp test/FixIt/fixit-cxx0x.cpp test/SemaCXX/class.cpp test/SemaCXX/cxx0x-class.cpp test/SemaTemplate/instantiate-static-var.cpp

Richard Smith richard-llvm at metafoo.co.uk
Thu Sep 29 16:18:35 PDT 2011


Author: rsmith
Date: Thu Sep 29 18:18:34 2011
New Revision: 140820

URL: http://llvm.org/viewvc/llvm-project?rev=140820&view=rev
Log:
Mark the ExtWarn for in-class initialization of static const float members as a GNU extension. Don't extend the scope of this extension to all literal types in C++0x mode.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CXX/class/class.static/class.static.data/p3.cpp
    cfe/trunk/test/FixIt/fixit-cxx0x.cpp
    cfe/trunk/test/SemaCXX/class.cpp
    cfe/trunk/test/SemaCXX/cxx0x-class.cpp
    cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=140820&r1=140819&r2=140820&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Sep 29 18:18:34 2011
@@ -4082,12 +4082,11 @@
 def err_in_class_initializer_bad_type : Error<
   "static data member of type %0 must be initialized out of line">;
 def ext_in_class_initializer_float_type : ExtWarn<
-  "in-class initializer for static data member of type %0 not allowed, "
-  "accepted as an extension">, InGroup<DiagGroup<"static-member-init">>;
-def ext_in_class_initializer_literal_type : ExtWarn<
+  "in-class initializer for static data member of type %0 is a GNU extension">,
+  InGroup<GNU>;
+def err_in_class_initializer_literal_type : Error<
   "in-class initializer for static data member of type %0 requires "
-  "'constexpr' specifier, accepted as an extension">,
-  InGroup<DiagGroup<"static-member-init">>;
+  "'constexpr' specifier">;
 def err_in_class_initializer_non_constant : Error<
   "in-class initializer is not a constant expression">;
 

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=140820&r1=140819&r2=140820&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Sep 29 18:18:34 2011
@@ -5875,13 +5875,6 @@
         VDecl->setInvalidDecl();
       }
 
-    // Suggest adding 'constexpr' in C++0x for literal types.
-    } else if (getLangOptions().CPlusPlus0x && T->isLiteralType()) {
-      Diag(VDecl->getLocation(), diag::ext_in_class_initializer_literal_type)
-        << T << Init->getSourceRange()
-        << FixItHint::CreateInsertion(VDecl->getLocStart(), "constexpr ");
-      VDecl->setConstexpr(true);
-
     // We allow floating-point constants as an extension.
     } else if (T->isFloatingType()) { // also permits complex, which is ok
       Diag(VDecl->getLocation(), diag::ext_in_class_initializer_float_type)
@@ -5893,6 +5886,14 @@
           << Init->getSourceRange();
         VDecl->setInvalidDecl();
       }
+
+    // Suggest adding 'constexpr' in C++0x for literal types.
+    } else if (getLangOptions().CPlusPlus0x && T->isLiteralType()) {
+      Diag(VDecl->getLocation(), diag::err_in_class_initializer_literal_type)
+        << T << Init->getSourceRange()
+        << FixItHint::CreateInsertion(VDecl->getLocStart(), "constexpr ");
+      VDecl->setConstexpr(true);
+
     } else {
       Diag(VDecl->getLocation(), diag::err_in_class_initializer_bad_type)
         << T << Init->getSourceRange();

Modified: cfe/trunk/test/CXX/class/class.static/class.static.data/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class/class.static/class.static.data/p3.cpp?rev=140820&r1=140819&r2=140820&view=diff
==============================================================================
--- cfe/trunk/test/CXX/class/class.static/class.static.data/p3.cpp (original)
+++ cfe/trunk/test/CXX/class/class.static/class.static.data/p3.cpp Thu Sep 29 18:18:34 2011
@@ -12,8 +12,8 @@
   static const int d;
 
   static constexpr double e = 0.0; // ok
-  static const double f = 0.0; // expected-warning {{accepted as an extension}}
-  static char *const g = 0; // expected-warning {{accepted as an extension}}
+  static const double f = 0.0; // expected-warning {{extension}}
+  static char *const g = 0; // expected-error {{requires 'constexpr' specifier}}
   static const NonLit h = NonLit(); // expected-error {{must be initialized out of line}}
 };
 

Modified: cfe/trunk/test/FixIt/fixit-cxx0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-cxx0x.cpp?rev=140820&r1=140819&r2=140820&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/fixit-cxx0x.cpp (original)
+++ cfe/trunk/test/FixIt/fixit-cxx0x.cpp Thu Sep 29 18:18:34 2011
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -verify -std=c++0x %s
 // RUN: cp %s %t
-// RUN: not %clang_cc1 -x c++ -std=c++0x -Werror -fixit %t
+// RUN: not %clang_cc1 -x c++ -std=c++0x -fixit %t
 // RUN: %clang_cc1 -Wall -pedantic -x c++ -std=c++0x %t
 
 /* This is a test of the various code modification hints that only
@@ -53,9 +53,7 @@
 #endif
 
   struct S {
-    static const double d = 0.0; // expected-warning {{accepted as an extension}}
-    // -> constexpr static const double d = 0.0;
-    static char *const p = 0; // expected-warning {{accepted as an extension}}
+    static char *const p = 0; // expected-error {{requires 'constexpr' specifier}}
     // -> constexpr static char *const p = 0;
   };
 }

Modified: cfe/trunk/test/SemaCXX/class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/class.cpp?rev=140820&r1=140819&r2=140820&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/class.cpp (original)
+++ cfe/trunk/test/SemaCXX/class.cpp Thu Sep 29 18:18:34 2011
@@ -173,8 +173,8 @@
   float foo();
 
   struct A {
-    static const float x = 5.0f; // expected-warning {{in-class initializer for static data member of type 'const float' not allowed}}
-    static const float y = foo(); // expected-warning {{in-class initializer for static data member of type 'const float' not allowed}} expected-error {{in-class initializer is not a constant expression}}
+    static const float x = 5.0f; // expected-warning {{in-class initializer for static data member of type 'const float' is a GNU extension}}
+    static const float y = foo(); // expected-warning {{in-class initializer for static data member of type 'const float' is a GNU extension}} expected-error {{in-class initializer is not a constant expression}}
   };
 }
 

Modified: cfe/trunk/test/SemaCXX/cxx0x-class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-class.cpp?rev=140820&r1=140819&r2=140820&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-class.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-class.cpp Thu Sep 29 18:18:34 2011
@@ -20,8 +20,8 @@
   float foo();
 
   struct A {
-    static const float x = 5.0f; // expected-warning {{requires 'constexpr' specifier}}
-    static const float y = foo(); // expected-warning {{requires 'constexpr' specifier}} expected-error {{must be initialized by a constant expression}}
+    static const float x = 5.0f; // expected-warning {{GNU extension}}
+    static const float y = foo(); // expected-warning {{GNU extension}} expected-error {{in-class initializer is not a constant expression}}
     static constexpr float x2 = 5.0f;
     static constexpr float y2 = foo(); // expected-error {{must be initialized by a constant expression}}
   };

Modified: cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp?rev=140820&r1=140819&r2=140820&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp Thu Sep 29 18:18:34 2011
@@ -11,7 +11,7 @@
 
 template<typename T>
 class Y {
-  static const T value = 0; // expected-warning{{in-class initializer for static data member of type 'const float' not allowed, accepted as an extension}}
+  static const T value = 0; // expected-warning{{in-class initializer for static data member of type 'const float' is a GNU extension}}
 };
 
 Y<float> fy; // expected-note{{in instantiation of template class 'Y<float>' requested here}}





More information about the cfe-commits mailing list