loplugin:staticconstfield improve warning message

Change-Id: I000dff6b1b6e33e1b2c5aa337c027c1edd7b1003
Reviewed-on: https://gerrit.libreoffice.org/68795
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2019-03-06 10:49:36 +02:00
parent 7e2a4f53a2
commit cfd080d00a
2 changed files with 10 additions and 7 deletions

View File

@ -15,6 +15,9 @@
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
/**
Look for fields which are const, which can be made static const
*/
namespace namespace
{ {
class StaticConstField : public loplugin::FilteringPlugin<StaticConstField> class StaticConstField : public loplugin::FilteringPlugin<StaticConstField>
@ -56,7 +59,7 @@ void StaticConstField::run()
for (auto const& pair : m_potentials) for (auto const& pair : m_potentials)
{ {
report(DiagnosticsEngine::Error, "field can be static const", pair.first->getLocation()) report(DiagnosticsEngine::Error, "const field can be static", pair.first->getLocation())
<< pair.first->getSourceRange(); << pair.first->getSourceRange();
for (CXXCtorInitializer const* init : pair.second.inits) for (CXXCtorInitializer const* init : pair.second.inits)
if (pair.first->getLocation() != init->getSourceLocation()) if (pair.first->getLocation() != init->getSourceLocation())

View File

@ -15,7 +15,7 @@
class Class1 class Class1
{ {
OUString const OUString const
m_field1; // expected-error {{field can be static const [loplugin:staticconstfield]}} m_field1; // expected-error {{const field can be static [loplugin:staticconstfield]}}
Class1() Class1()
: m_field1("xxxx") : m_field1("xxxx")
// expected-note@-1 {{init here [loplugin:staticconstfield]}} // expected-note@-1 {{init here [loplugin:staticconstfield]}}
@ -27,7 +27,7 @@ class Class1
class Class2 class Class2
{ {
OString const OString const
m_field2; // expected-error {{field can be static const [loplugin:staticconstfield]}} m_field2; // expected-error {{const field can be static [loplugin:staticconstfield]}}
Class2() Class2()
: m_field2("yyyy") : m_field2("yyyy")
// expected-note@-1 {{init here [loplugin:staticconstfield]}} // expected-note@-1 {{init here [loplugin:staticconstfield]}}
@ -54,12 +54,12 @@ class Class5
ONE ONE
}; };
float const float const
m_fielda1; // expected-error {{field can be static const [loplugin:staticconstfield]}} m_fielda1; // expected-error {{const field can be static [loplugin:staticconstfield]}}
int const m_fielda2; // expected-error {{field can be static const [loplugin:staticconstfield]}} int const m_fielda2; // expected-error {{const field can be static [loplugin:staticconstfield]}}
bool const bool const
m_fielda3; // expected-error {{field can be static const [loplugin:staticconstfield]}} m_fielda3; // expected-error {{const field can be static [loplugin:staticconstfield]}}
Enum const Enum const
m_fielda4; // expected-error {{field can be static const [loplugin:staticconstfield]}} m_fielda4; // expected-error {{const field can be static [loplugin:staticconstfield]}}
Class5() Class5()
: m_fielda1(1.0) : m_fielda1(1.0)
// expected-note@-1 {{init here [loplugin:staticconstfield]}} // expected-note@-1 {{init here [loplugin:staticconstfield]}}