parent
b8ba0ae00e
commit
fb1170b10b
|
@ -2082,6 +2082,8 @@ bool CheckClass::isMemberVar(const Scope *scope, const Token *tok) const
|
|||
|
||||
for (const Variable& var : scope->varlist) {
|
||||
if (var.name() == tok->str()) {
|
||||
if (Token::Match(tok, "%name% ::"))
|
||||
continue;
|
||||
const Token* fqTok = tok;
|
||||
while (Token::Match(fqTok->tokAt(-2), "%name% ::"))
|
||||
fqTok = fqTok->tokAt(-2);
|
||||
|
|
|
@ -3745,6 +3745,8 @@ void Tokenizer::setVarIdClassFunction(const std::string &classname,
|
|||
continue;
|
||||
if (Token::Match(tok2->tokAt(-2), "!!this .") && !Token::simpleMatch(tok2->tokAt(-5), "( * this ) ."))
|
||||
continue;
|
||||
if (Token::Match(tok2, "%name% ::"))
|
||||
continue;
|
||||
|
||||
const std::map<std::string,int>::const_iterator it = varlist.find(tok2->str());
|
||||
if (it != varlist.end()) {
|
||||
|
|
|
@ -222,6 +222,7 @@ private:
|
|||
TEST_CASE(constPtrToConstPtr);
|
||||
TEST_CASE(constTrailingReturnType);
|
||||
TEST_CASE(staticArrayPtrOverload);
|
||||
TEST_CASE(qualifiedNameMember); // #10872
|
||||
|
||||
TEST_CASE(initializerListOrder);
|
||||
TEST_CASE(initializerListUsage);
|
||||
|
@ -6823,6 +6824,22 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void qualifiedNameMember() { // #10872
|
||||
Settings s;
|
||||
s.severity.enable(Severity::style);
|
||||
s.debugwarnings = true;
|
||||
LOAD_LIB_2(s.library, "std.cfg");
|
||||
checkConst("struct data {};\n"
|
||||
" struct S {\n"
|
||||
" std::vector<data> std;\n"
|
||||
" void f();\n"
|
||||
"};\n"
|
||||
"void S::f() {\n"
|
||||
" std::vector<data>::const_iterator end = std.end();\n"
|
||||
"}\n", &s);
|
||||
ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:4]: (style, inconclusive) Technically the member function 'S::f' can be const.\n", errout.str());
|
||||
}
|
||||
|
||||
#define checkInitializerListOrder(code) checkInitializerListOrder_(code, __FILE__, __LINE__)
|
||||
void checkInitializerListOrder_(const char code[], const char* file, int line) {
|
||||
// Clear the error log
|
||||
|
|
|
@ -133,6 +133,7 @@ private:
|
|||
TEST_CASE(varid_in_class19);
|
||||
TEST_CASE(varid_in_class20); // #7267
|
||||
TEST_CASE(varid_in_class21); // #7788
|
||||
TEST_CASE(varid_in_class22); // #10872
|
||||
TEST_CASE(varid_namespace_1); // #7272
|
||||
TEST_CASE(varid_namespace_2); // #7000
|
||||
TEST_CASE(varid_namespace_3); // #8627
|
||||
|
@ -1910,6 +1911,30 @@ private:
|
|||
ASSERT_EQUALS(expected, tokenize(code, "test.cpp"));
|
||||
}
|
||||
|
||||
void varid_in_class22() {
|
||||
const char code[] = "struct data {};\n"
|
||||
" struct S {\n"
|
||||
" std::vector<data> std;\n"
|
||||
" void f();\n"
|
||||
"};\n"
|
||||
"void S::f() {\n"
|
||||
" std::vector<data>::const_iterator end = std.end();\n"
|
||||
" for (std::vector<data>::const_iterator i = std.begin(); i != end; ++i) {}\n"
|
||||
"}\n";
|
||||
|
||||
const char expected[] = "1: struct data { } ;\n"
|
||||
"2: struct S {\n"
|
||||
"3: std :: vector < data > std@1 ;\n"
|
||||
"4: void f ( ) ;\n"
|
||||
"5: } ;\n"
|
||||
"6: void S :: f ( ) {\n"
|
||||
"7: std :: vector < data > :: const_iterator end@2 ; end@2 = std@1 . end ( ) ;\n"
|
||||
"8: for ( std :: vector < data > :: const_iterator i@3 = std@1 . begin ( ) ; i@3 != end@2 ; ++ i@3 ) { }\n"
|
||||
"9: }\n";
|
||||
|
||||
ASSERT_EQUALS(expected, tokenize(code, "test.cpp"));
|
||||
}
|
||||
|
||||
void varid_namespace_1() { // #7272
|
||||
const char code[] = "namespace Blah {\n"
|
||||
" struct foo { int x;};\n"
|
||||
|
|
Loading…
Reference in New Issue