From 2d23ec29805f54edb3243022c64d752b8fbe5f46 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 30 Sep 2011 00:33:19 +0000 Subject: [PATCH] Suggest adding 'constexpr' if the GNU extension for in-class initializers for static const float members is used in C++11 mode. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140828 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ lib/Sema/SemaDecl.cpp | 4 ++++ test/CXX/class/class.static/class.static.data/p3.cpp | 2 +- test/SemaCXX/cxx0x-class.cpp | 4 ++-- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 52b288f49c..5330fb3956 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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; +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">; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 7bb3aa1511..3ba9464cb1 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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)) { 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 51b93a2e8f..031c376648 100644 --- a/test/CXX/class/class.static/class.static.data/p3.cpp +++ b/test/CXX/class/class.static/class.static.data/p3.cpp @@ -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}} }; diff --git a/test/SemaCXX/cxx0x-class.cpp b/test/SemaCXX/cxx0x-class.cpp index bd857e07fe..5d12b83ccd 100644 --- a/test/SemaCXX/cxx0x-class.cpp +++ b/test/SemaCXX/cxx0x-class.cpp @@ -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}} }; -- 2.40.0