Handle pointers to const member functions in Tokenizer::simplifyFunctionPointers() (#6603)
This commit is contained in:
parent
c4ceb97cea
commit
ac867b4220
|
@ -5270,10 +5270,13 @@ void Tokenizer:: simplifyFunctionPointers()
|
|||
tok = tok->next();
|
||||
|
||||
// check that the declaration ends
|
||||
const Token *endTok = tok->link()->next()->link();
|
||||
if (!Token::Match(endTok, ") ;|,|)|=|[|{"))
|
||||
Token *endTok = tok->link()->next()->link();
|
||||
if (!Token::Match(endTok, ") const| ;|,|)|=|[|{"))
|
||||
continue;
|
||||
|
||||
if (endTok->strAt(1) == "const")
|
||||
endTok->deleteNext();
|
||||
|
||||
// ok simplify this function pointer to an ordinary pointer
|
||||
Token::eraseTokens(tok->link(), endTok->next());
|
||||
tok->link()->deleteThis();
|
||||
|
|
|
@ -2610,10 +2610,10 @@ private:
|
|||
const char expected[] = "C f1 ( ) ; "
|
||||
"C * f2 ; " // this gets simplified to a regular pointer
|
||||
"C ( & f3 ) ( ) ; "
|
||||
"C * f4 ; "
|
||||
"C ( C :: * f5 ) ( ) const ; "
|
||||
"C * f6 ; " // volatile is removed
|
||||
"C ( C :: * f7 ) ( ) const ;"; // volatile is removed
|
||||
"C * f4 ; " // this gets simplified to a regular pointer
|
||||
"C * f5 ; " // this gets simplified to a regular pointer
|
||||
"C * f6 ; " // this gets simplified to a regular pointer
|
||||
"C * f7 ;"; // this gets simplified to a regular pointer
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Unspecified, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
@ -2639,10 +2639,10 @@ private:
|
|||
const char expected[] = "const C f1 ( ) ; "
|
||||
"const C * f2 ; " // this gets simplified to a regular pointer
|
||||
"const C ( & f3 ) ( ) ; "
|
||||
"const C * f4 ; "
|
||||
"const C ( C :: * f5 ) ( ) const ; "
|
||||
"const C * f6 ; " // volatile is removed
|
||||
"const C ( C :: * f7 ) ( ) const ;"; // volatile is removed
|
||||
"const C * f4 ; " // this gets simplified to a regular pointer
|
||||
"const C * f5 ; " // this gets simplified to a regular pointer
|
||||
"const C * f6 ; " // this gets simplified to a regular pointer
|
||||
"const C * f7 ;"; // this gets simplified to a regular pointer
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Unspecified, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
@ -2667,10 +2667,10 @@ private:
|
|||
const char expected[] = "const C f1 ( ) ; "
|
||||
"const C * f2 ; " // this gets simplified to a regular pointer
|
||||
"const C ( & f3 ) ( ) ; "
|
||||
"const C * f4 ; "
|
||||
"const C ( C :: * f5 ) ( ) const ; "
|
||||
"const C * f6 ; " // volatile is removed
|
||||
"const C ( C :: * f7 ) ( ) const ;"; // volatile is removed
|
||||
"const C * f4 ; " // this gets simplified to a regular pointer
|
||||
"const C * f5 ; " // this gets simplified to a regular pointer
|
||||
"const C * f6 ; " // this gets simplified to a regular pointer
|
||||
"const C * f7 ;"; // this gets simplified to a regular pointer
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Unspecified, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
@ -2695,10 +2695,10 @@ private:
|
|||
const char expected[] = "C * f1 ( ) ; "
|
||||
"C * * f2 ; " // this gets simplified to a regular pointer
|
||||
"C * ( & f3 ) ( ) ; "
|
||||
"C * * f4 ; "
|
||||
"C * ( C :: * f5 ) ( ) const ; "
|
||||
"C * * f6 ; " // volatile is removed
|
||||
"C * ( C :: * f7 ) ( ) const ;"; // volatile is removed
|
||||
"C * * f4 ; " // this gets simplified to a regular pointer
|
||||
"C * * f5 ; " // this gets simplified to a regular pointer
|
||||
"C * * f6 ; " // this gets simplified to a regular pointer
|
||||
"C * * f7 ;"; // this gets simplified to a regular pointer
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Unspecified, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
@ -2723,10 +2723,10 @@ private:
|
|||
const char expected[] = "const C * f1 ( ) ; "
|
||||
"const C * * f2 ; " // this gets simplified to a regular pointer
|
||||
"const C * ( & f3 ) ( ) ; "
|
||||
"const C * * f4 ; "
|
||||
"const C * ( C :: * f5 ) ( ) const ; "
|
||||
"const C * * f6 ; " // volatile is removed
|
||||
"const C * ( C :: * f7 ) ( ) const ;"; // volatile is removed
|
||||
"const C * * f4 ; " // this gets simplified to a regular pointer
|
||||
"const C * * f5 ; " // this gets simplified to a regular pointer
|
||||
"const C * * f6 ; " // this gets simplified to a regular pointer
|
||||
"const C * * f7 ;"; // this gets simplified to a regular pointer
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Unspecified, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
@ -2752,10 +2752,10 @@ private:
|
|||
const char expected[] = "const C * f1 ( ) ; "
|
||||
"const C * * f2 ; " // this gets simplified to a regular pointer
|
||||
"const C * ( & f3 ) ( ) ; "
|
||||
"const C * * f4 ; "
|
||||
"const C * ( C :: * f5 ) ( ) const ; "
|
||||
"const C * * f6 ; " // volatile is removed
|
||||
"const C * ( C :: * f7 ) ( ) const ;"; // volatile is removed
|
||||
"const C * * f4 ; " // this gets simplified to a regular pointer
|
||||
"const C * * f5 ; " // this gets simplified to a regular pointer
|
||||
"const C * * f6 ; " // this gets simplified to a regular pointer
|
||||
"const C * * f7 ;"; // this gets simplified to a regular pointer
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Unspecified, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
@ -2898,9 +2898,9 @@ private:
|
|||
|
||||
// The expected result..
|
||||
const char expected[] = "B :: C * f1 ; "
|
||||
"B :: C ( B :: C :: * f2 ) ( ) const ; "
|
||||
"B :: C * f2 ; "
|
||||
"B :: C * f3 ; "
|
||||
"B :: C ( B :: C :: * f4 ) ( ) const ;";
|
||||
"B :: C * f4 ;";
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Unspecified, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
@ -2936,9 +2936,9 @@ private:
|
|||
|
||||
// The expected result..
|
||||
const char expected[] = "A :: B :: C * f1 ; "
|
||||
"A :: B :: C ( A :: B :: C :: * f2 ) ( ) const ; "
|
||||
"A :: B :: C * f2 ; "
|
||||
"A :: B :: C * f3 ; "
|
||||
"A :: B :: C ( A :: B :: C :: * f4 ) ( ) const ;";
|
||||
"A :: B :: C * f4 ;";
|
||||
ASSERT_EQUALS(expected, tok(code, true, Settings::Unspecified, false));
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
|
|
@ -90,6 +90,7 @@ private:
|
|||
TEST_CASE(localvar44); // ticket #4020
|
||||
TEST_CASE(localvar45); // ticket #4899
|
||||
TEST_CASE(localvar46); // ticket #5491 (C++11 style initialization)
|
||||
TEST_CASE(localvar47); // ticket #6603
|
||||
TEST_CASE(localvaralias1);
|
||||
TEST_CASE(localvaralias2); // ticket #1637
|
||||
TEST_CASE(localvaralias3); // ticket #1639
|
||||
|
@ -1885,6 +1886,14 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvar47() { // #6603
|
||||
functionVariableUsage("void f() {\n"
|
||||
" int (SfxUndoManager::*retrieveCount)(bool) const\n"
|
||||
" = (flag) ? &SfxUndoManager::foo : &SfxUndoManager::bar;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'retrieveCount' is assigned a value that is never used.\n", errout.str());
|
||||
}
|
||||
|
||||
void localvaralias1() {
|
||||
functionVariableUsage("void foo()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue