r173835 - Don't fixit/recover from -Wstatic-float-init when it's not an error.
David Blaikie
dblaikie at gmail.com
Tue Jan 29 13:40:37 PST 2013
Author: dblaikie
Date: Tue Jan 29 15:40:37 2013
New Revision: 173835
URL: http://llvm.org/viewvc/llvm-project?rev=173835&view=rev
Log:
Don't fixit/recover from -Wstatic-float-init when it's not an error.
Fix to change r173414 that lead to Clang changing const to constexpr even under
-Wno-static-float-init.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/cxx0x-class.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=173835&r1=173834&r2=173835&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jan 29 15:40:37 2013
@@ -7203,11 +7203,15 @@ void Sema::AddInitializerToDecl(Decl *Re
// 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();
Modified: cfe/trunk/test/SemaCXX/cxx0x-class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-class.cpp?rev=173835&r1=173834&r2=173835&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-class.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-class.cpp Tue Jan 29 15:40:37 2013
@@ -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'}}
};
More information about the cfe-commits
mailing list