]> granicus.if.org Git - clang/commitdiff
Move -Wstatic-float-init fixit into a note & don't recover as if constexpr
authorDavid Blaikie <dblaikie@gmail.com>
Tue, 29 Jan 2013 22:26:08 +0000 (22:26 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Tue, 29 Jan 2013 22:26:08 +0000 (22:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173841 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/CXX/class/class.union/p2-0x.cpp
test/SemaCXX/cxx0x-class.cpp
test/SemaCXX/warn-static-const-float.cpp

index 6e27d1388bcc4b8cf5100c68678cb2bcbbfb7695..326b96e626c586d00504330993e1208fc46ce6df 100644 (file)
@@ -5311,6 +5311,7 @@ def ext_in_class_initializer_float_type : ExtWarn<
 def ext_in_class_initializer_float_type_cxx11 : ExtWarn<
   "in-class initializer for static data member of type %0 requires "
   "'constexpr' specifier">, InGroup<StaticFloatInit>, DefaultError;
+def note_in_class_initializer_float_type_cxx11 : Note<"add 'constexpr'">;
 def err_in_class_initializer_literal_type : Error<
   "in-class initializer for static data member of type %0 requires "
   "'constexpr' specifier">;
index 702d38280a6c811f3119241cd14a7c2d97a4c888..60b67602c3f010eb5aee3c8792a964f85cd6dcea 100644 (file)
@@ -7203,15 +7203,12 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init,
       // In C++98, this is a GNU extension. In C++11, it is not, but we support
       // it anyway and provide a fixit to add the 'constexpr'.
       if (getLangOpts().CPlusPlus11) {
-        SemaDiagnosticBuilder D = Diag(VDecl->getLocation(),
-             diag::ext_in_class_initializer_float_type_cxx11);
-        D << DclT << Init->getSourceRange();
-        if (Diags.getDiagnosticLevel(diag::warn_initializer_out_of_order,
-                                     VDecl->getLocation()) >=
-            DiagnosticsEngine::Error) {
-          D << FixItHint::CreateInsertion(VDecl->getLocStart(), "constexpr ");
-          VDecl->setConstexpr(true);
-        }
+        Diag(VDecl->getLocation(),
+             diag::ext_in_class_initializer_float_type_cxx11)
+            << DclT << Init->getSourceRange();
+        Diag(VDecl->getLocStart(),
+             diag::note_in_class_initializer_float_type_cxx11)
+            << FixItHint::CreateInsertion(VDecl->getLocStart(), "constexpr ");
       } else {
         Diag(VDecl->getLocation(), diag::ext_in_class_initializer_float_type)
           << DclT << Init->getSourceRange();
index 0d104e037dcedded4e4847397edcc7707c5ea42f..1607bac80293f6df6e7234ffccf064245001bf9b 100644 (file)
@@ -13,7 +13,7 @@ struct S {
   static const int d2 = 0;
 
   static constexpr double e = 0.0; // ok
-  static const double f = 0.0; // expected-error {{requires 'constexpr' specifier}}
+  static const double f = 0.0; // expected-error {{requires 'constexpr' specifier}} expected-note {{add 'constexpr'}}
   static char *const g = 0; // expected-error {{requires 'constexpr' specifier}}
   static const NonLit h = NonLit(); // expected-error {{must be initialized out of line}}
 };
index 19a3ea2e1bb02463cebe9ba476e0b3422768ef06..5fb8a671e31b5a975ebe47cacc4b9559a9abada4 100644 (file)
@@ -7,7 +7,7 @@ union U1 {
   static const int k2 = k1;
   static int k3 = k2; // expected-error {{non-const static data member must be initialized out of line}}
   static constexpr double k4 = k2;
-  static const double k5 = k4; // expected-error {{requires 'constexpr' specifier}}
+  static const double k5 = k4; // expected-error {{requires 'constexpr' specifier}} expected-note {{add 'constexpr'}}
   int n[k1 + 3];
 };
 
index 4e0d5bc3d70266d9314f753bfb6c3833618851da..074591e7063cd225c11994c10e997d697b4a6c20 100644 (file)
@@ -20,8 +20,8 @@ namespace rdar8367341 {
   float foo(); // expected-note {{here}}
 
   struct A {
-    static const float x = 5.0f; // expected-warning {{requires 'constexpr'}}
-    static const float y = foo(); // expected-warning {{requires 'constexpr'}}
+    static const float x = 5.0f; // expected-warning {{requires 'constexpr'}} expected-note {{add 'constexpr'}}
+    static const float y = foo(); // expected-warning {{requires 'constexpr'}} expected-note {{add 'constexpr'}}
     static constexpr float x2 = 5.0f;
     static constexpr float y2 = foo(); // expected-error {{must be initialized by a constant expression}} expected-note {{non-constexpr function 'foo'}}
   };
index a669c85903f168c41d2198d9da422d2c6d3fe9f5..481a410489bb932de3a32a04f8075a4f89dcbf82 100644 (file)
 #if NONE
 // expected-no-diagnostics
 #elif ERR
-// expected-error@19 {{in-class initializer for static data member of type 'const double' requires 'constexpr' specifier}}
+// expected-error@20 {{in-class initializer for static data member of type 'const double' requires 'constexpr' specifier}}
+// expected-note@20 {{add 'constexpr'}}
 #elif EXT
-// expected-warning@19 {{in-class initializer for static data member of type 'const double' is a GNU extension}}
+// expected-warning@20 {{in-class initializer for static data member of type 'const double' is a GNU extension}}
 #endif
 
 struct X {