diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-01-25 04:22:16 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-01-25 04:22:16 +0000 |
commit | cf656385ea2da9c7c29eff9c2aa7a89d81fb5703 (patch) | |
tree | d672aa132f2903b334fa317c7d22cf276e58187d /clang/lib/Sema/SemaDecl.cpp | |
parent | 44f750a3e58eb6ae84a4476aa4befc0bb406dffa (diff) | |
download | bcm5719-llvm-cf656385ea2da9c7c29eff9c2aa7a89d81fb5703.tar.gz bcm5719-llvm-cf656385ea2da9c7c29eff9c2aa7a89d81fb5703.zip |
Sync 'in class initialization of static const double' extension up with GCC,
and split it out of -Wgnu into its own warning flag.
* In C++11, this is now a hard error (GCC has no extension here in C++11 mode).
The error can be disabled with -Wno-static-float-init, and has a fixit to
add 'constexpr'.
* In C++98, this is still an ExtWarn, but is now controlled by
-Wstatic-float-init as well as -Wgnu.
llvm-svn: 173414
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 538434db002..9efcb52d148 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -7128,17 +7128,23 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, // We allow foldable floating-point constants as an extension. } else if (DclT->isFloatingType()) { // also permits complex, which is ok - Diag(VDecl->getLocation(), diag::ext_in_class_initializer_float_type) - << DclT << Init->getSourceRange(); - if (getLangOpts().CPlusPlus11) + // 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::note_in_class_initializer_float_type_constexpr) + diag::ext_in_class_initializer_float_type_cxx11) + << DclT << Init->getSourceRange() << FixItHint::CreateInsertion(VDecl->getLocStart(), "constexpr "); + VDecl->setConstexpr(true); + } else { + Diag(VDecl->getLocation(), diag::ext_in_class_initializer_float_type) + << DclT << Init->getSourceRange(); - if (!Init->isValueDependent() && !Init->isEvaluatable(Context)) { - Diag(Init->getExprLoc(), diag::err_in_class_initializer_non_constant) - << Init->getSourceRange(); - VDecl->setInvalidDecl(); + if (!Init->isValueDependent() && !Init->isEvaluatable(Context)) { + Diag(Init->getExprLoc(), diag::err_in_class_initializer_non_constant) + << Init->getSourceRange(); + VDecl->setInvalidDecl(); + } } // Suggest adding 'constexpr' in C++11 for literal types. |