]> granicus.if.org Git - clang/commitdiff
Don't fixit/recover from -Wstatic-float-init when it's not an error.
authorDavid Blaikie <dblaikie@gmail.com>
Tue, 29 Jan 2013 21:40:37 +0000 (21:40 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Tue, 29 Jan 2013 21:40:37 +0000 (21:40 +0000)
Fix to change r173414 that lead to Clang changing const to constexpr even under
-Wno-static-float-init.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173835 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/cxx0x-class.cpp

index 33506401cfe8f68c6dc07475fb1b70117c04d095..702d38280a6c811f3119241cd14a7c2d97a4c888 100644 (file)
@@ -7203,11 +7203,15 @@ 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) {
-        Diag(VDecl->getLocation(),
-             diag::ext_in_class_initializer_float_type_cxx11)
-          << DclT << Init->getSourceRange()
-          << FixItHint::CreateInsertion(VDecl->getLocStart(), "constexpr ");
-        VDecl->setConstexpr(true);
+        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);
+        }
       } else {
         Diag(VDecl->getLocation(), diag::ext_in_class_initializer_float_type)
           << DclT << Init->getSourceRange();
index 5532bcea3eb9df7a1c2dca114d63c816c42c7239..4e0d5bc3d70266d9314f753bfb6c3833618851da 100644 (file)
@@ -17,11 +17,11 @@ public:
 };
 
 namespace rdar8367341 {
-  float foo(); // expected-note 2{{here}}
+  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'}} expected-error {{constexpr variable 'y' must be initialized by a constant expression}} expected-note {{non-constexpr function 'foo'}}
+    static const float y = foo(); // expected-warning {{requires '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'}}
   };