]> granicus.if.org Git - clang/commitdiff
Suggest adding 'constexpr' if the GNU extension for in-class initializers for static...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 30 Sep 2011 00:33:19 +0000 (00:33 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 30 Sep 2011 00:33:19 +0000 (00:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140828 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/CXX/class/class.static/class.static.data/p3.cpp
test/SemaCXX/cxx0x-class.cpp

index 52b288f49cc14622f41d22564950fbea6f2f0597..5330fb395635543d2cd89ac9a25545adc1a459fc 100644 (file)
@@ -4084,6 +4084,8 @@ def err_in_class_initializer_bad_type : Error<
 def ext_in_class_initializer_float_type : ExtWarn<
   "in-class initializer for static data member of type %0 is a GNU extension">,
   InGroup<GNU>;
+def note_in_class_initializer_float_type_constexpr : Note<
+  "use 'constexpr' specifier to silence this warning">;
 def err_in_class_initializer_literal_type : Error<
   "in-class initializer for static data member of type %0 requires "
   "'constexpr' specifier">;
index 7bb3aa15110258f2548c14f0d6391f32f560ea6d..3ba9464cb12f3946b83fdaba4712ba31e235f876 100644 (file)
@@ -5879,6 +5879,10 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init,
     } else if (T->isFloatingType()) { // also permits complex, which is ok
       Diag(VDecl->getLocation(), diag::ext_in_class_initializer_float_type)
         << T << Init->getSourceRange();
+      if (getLangOptions().CPlusPlus0x)
+        Diag(VDecl->getLocation(),
+             diag::note_in_class_initializer_float_type_constexpr)
+          << FixItHint::CreateInsertion(VDecl->getLocStart(), "constexpr ");
 
       if (!Init->isValueDependent() &&
           !Init->isConstantInitializer(Context, false)) {
index 51b93a2e8f953023206451f04c149f4167deed4d..031c37664882c6a5e6dafde78a6e4e05532f9557 100644 (file)
@@ -12,7 +12,7 @@ struct S {
   static const int d;
 
   static constexpr double e = 0.0; // ok
-  static const double f = 0.0; // expected-warning {{extension}}
+  static const double f = 0.0; // expected-warning {{extension}} expected-note {{use 'constexpr' specifier}}
   static char *const g = 0; // expected-error {{requires 'constexpr' specifier}}
   static const NonLit h = NonLit(); // expected-error {{must be initialized out of line}}
 };
index bd857e07febed053748f7b06934979b93a2e4837..5d12b83ccd53e96b91647b584ab3f63ca480a675 100644 (file)
@@ -20,8 +20,8 @@ namespace rdar8367341 {
   float foo();
 
   struct A {
-    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 const float x = 5.0f; // expected-warning {{GNU extension}} expected-note {{use 'constexpr' specifier to silence this warning}}
+    static const float y = foo(); // expected-warning {{GNU extension}} expected-note {{use 'constexpr' specifier to silence this warning}} 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}}
   };