Skip to content

Commit f1c33b2

Browse files
Fix #14366 FN functionStatic with unknown base class (#8085)
1 parent 2905857 commit f1c33b2

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

gui/codeeditor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ void Highlighter::highlightBlock(const QString &text)
246246
}
247247
}
248248

249-
void Highlighter::applyFormat(HighlightingRule &rule)
249+
void Highlighter::applyFormat(HighlightingRule &rule) const
250250
{
251251
switch (rule.ruleRole) {
252252
case RuleRole::Keyword:

gui/codeeditor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Highlighter : public QSyntaxHighlighter {
6565
RuleRole ruleRole;
6666
};
6767

68-
void applyFormat(HighlightingRule &rule);
68+
void applyFormat(HighlightingRule &rule) const;
6969

7070
QList<HighlightingRule> mHighlightingRules;
7171
QList<HighlightingRule> mHighlightingRulesWithSymbols;

lib/checkclass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,6 +2292,10 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok) const
22922292

22932293
if (tok->isKeyword() || tok->isStandardType())
22942294
return false;
2295+
if (tok->variable() && (tok->variable()->isArgument() || tok->variable()->isLocal()))
2296+
return false;
2297+
if (tok->function() || tok->type() || tok->enumerator())
2298+
return false;
22952299

22962300
for (const Variable& var : scope->varlist) {
22972301
if (var.name() == tok->str()) {

test/testclass.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6731,6 +6731,7 @@ class TestClass : public TestFixture {
67316731
"struct S<0> {};\n"
67326732
"struct D : S<150> {};\n");
67336733
// don't hang
6734+
ignore_errout();
67346735
}
67356736

67366737
void const93() { // #12162
@@ -6785,6 +6786,36 @@ class TestClass : public TestFixture {
67856786
" B::g(0);\n"
67866787
"}\n");
67876788
ASSERT_EQUALS("", errout_str());
6789+
6790+
checkConst("struct S {\n" // #14366
6791+
" void f();\n"
6792+
"};\n"
6793+
"struct T : U {\n"
6794+
" void g(S* s) {\n"
6795+
" s->f();\n"
6796+
" }\n"
6797+
" void h() {\n"
6798+
" S s;\n"
6799+
" s.f();\n"
6800+
" }\n"
6801+
"};\n");
6802+
ASSERT_EQUALS("[test.cpp:5:10]: (style) Either there is a missing 'override', or the member function 'T::g' can be static. [functionStatic]\n"
6803+
"[test.cpp:8:10]: (style) Either there is a missing 'override', or the member function 'T::h' can be static. [functionStatic]\n",
6804+
errout_str());
6805+
6806+
checkConst("enum E { E0 };\n"
6807+
"int f();\n"
6808+
"struct S : U {\n"
6809+
" E g() {\n"
6810+
" return E0;\n"
6811+
" }\n"
6812+
" int h() {\n"
6813+
" return f();\n"
6814+
" }\n"
6815+
"};\n");
6816+
ASSERT_EQUALS("[test.cpp:4:7]: (style) Either there is a missing 'override', or the member function 'S::g' can be static. [functionStatic]\n"
6817+
"[test.cpp:7:9]: (style) Either there is a missing 'override', or the member function 'S::h' can be static. [functionStatic]\n",
6818+
errout_str());
67886819
}
67896820

67906821
void const97() { // #13301

0 commit comments

Comments
 (0)