From: David Blaikie Date: Tue, 29 Jan 2013 22:26:08 +0000 (+0000) Subject: Move -Wstatic-float-init fixit into a note & don't recover as if constexpr X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a367e9de80eb05e78f06dc35c1e050799e735282;p=clang Move -Wstatic-float-init fixit into a note & don't recover as if constexpr git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173841 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 6e27d1388b..326b96e626 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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, 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">; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 702d38280a..60b67602c3 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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(); diff --git a/test/CXX/class/class.static/class.static.data/p3.cpp b/test/CXX/class/class.static/class.static.data/p3.cpp index 0d104e037d..1607bac802 100644 --- a/test/CXX/class/class.static/class.static.data/p3.cpp +++ b/test/CXX/class/class.static/class.static.data/p3.cpp @@ -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}} }; diff --git a/test/CXX/class/class.union/p2-0x.cpp b/test/CXX/class/class.union/p2-0x.cpp index 19a3ea2e1b..5fb8a671e3 100644 --- a/test/CXX/class/class.union/p2-0x.cpp +++ b/test/CXX/class/class.union/p2-0x.cpp @@ -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]; }; diff --git a/test/SemaCXX/cxx0x-class.cpp b/test/SemaCXX/cxx0x-class.cpp index 4e0d5bc3d7..074591e706 100644 --- a/test/SemaCXX/cxx0x-class.cpp +++ b/test/SemaCXX/cxx0x-class.cpp @@ -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'}} }; diff --git a/test/SemaCXX/warn-static-const-float.cpp b/test/SemaCXX/warn-static-const-float.cpp index a669c85903..481a410489 100644 --- a/test/SemaCXX/warn-static-const-float.cpp +++ b/test/SemaCXX/warn-static-const-float.cpp @@ -10,9 +10,10 @@ #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 {