diff --git a/gui/codeeditor.cpp b/gui/codeeditor.cpp index 7e7f2cbc37c..b6d88a061d3 100644 --- a/gui/codeeditor.cpp +++ b/gui/codeeditor.cpp @@ -246,7 +246,7 @@ void Highlighter::highlightBlock(const QString &text) } } -void Highlighter::applyFormat(HighlightingRule &rule) +void Highlighter::applyFormat(HighlightingRule &rule) const { switch (rule.ruleRole) { case RuleRole::Keyword: diff --git a/gui/codeeditor.h b/gui/codeeditor.h index 4f6d07e1e36..9508c562c41 100644 --- a/gui/codeeditor.h +++ b/gui/codeeditor.h @@ -65,7 +65,7 @@ class Highlighter : public QSyntaxHighlighter { RuleRole ruleRole; }; - void applyFormat(HighlightingRule &rule); + void applyFormat(HighlightingRule &rule) const; QList mHighlightingRules; QList mHighlightingRulesWithSymbols; diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 2949d3c57a7..11951411f8f 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -2292,6 +2292,10 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok) const if (tok->isKeyword() || tok->isStandardType()) return false; + if (tok->variable() && (tok->variable()->isArgument() || tok->variable()->isLocal())) + return false; + if (tok->function() || tok->type() || tok->enumerator()) + return false; for (const Variable& var : scope->varlist) { if (var.name() == tok->str()) { diff --git a/test/testclass.cpp b/test/testclass.cpp index 21457f15bfc..46c61d41c37 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -6731,6 +6731,7 @@ class TestClass : public TestFixture { "struct S<0> {};\n" "struct D : S<150> {};\n"); // don't hang + ignore_errout(); } void const93() { // #12162 @@ -6785,6 +6786,36 @@ class TestClass : public TestFixture { " B::g(0);\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + checkConst("struct S {\n" // #14366 + " void f();\n" + "};\n" + "struct T : U {\n" + " void g(S* s) {\n" + " s->f();\n" + " }\n" + " void h() {\n" + " S s;\n" + " s.f();\n" + " }\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:5:10]: (style) Either there is a missing 'override', or the member function 'T::g' can be static. [functionStatic]\n" + "[test.cpp:8:10]: (style) Either there is a missing 'override', or the member function 'T::h' can be static. [functionStatic]\n", + errout_str()); + + checkConst("enum E { E0 };\n" + "int f();\n" + "struct S : U {\n" + " E g() {\n" + " return E0;\n" + " }\n" + " int h() {\n" + " return f();\n" + " }\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:4:7]: (style) Either there is a missing 'override', or the member function 'S::g' can be static. [functionStatic]\n" + "[test.cpp:7:9]: (style) Either there is a missing 'override', or the member function 'S::h' can be static. [functionStatic]\n", + errout_str()); } void const97() { // #13301