Fix varid 0 with function pointer and virtual methods

This commit is contained in:
Richard Quirk 2011-11-09 21:02:41 +01:00
parent 2d00cabee1
commit f56aa19fac
2 changed files with 28 additions and 0 deletions

View File

@ -3373,6 +3373,9 @@ void Tokenizer::setVarId()
if (tok->str() == "throw") if (tok->str() == "throw")
continue; continue;
if (tok->str() == "virtual")
continue;
if (tok->str() == "unsigned") if (tok->str() == "unsigned")
tok = tok->next(); tok = tok->next();

View File

@ -300,6 +300,7 @@ private:
TEST_CASE(functionpointer1); TEST_CASE(functionpointer1);
TEST_CASE(functionpointer2); TEST_CASE(functionpointer2);
TEST_CASE(functionpointer3); TEST_CASE(functionpointer3);
TEST_CASE(functionpointer4);
TEST_CASE(removeRedundantAssignment); TEST_CASE(removeRedundantAssignment);
@ -4872,6 +4873,30 @@ private:
ASSERT_EQUALS(expected, simplifyFunctionPointers(code)); ASSERT_EQUALS(expected, simplifyFunctionPointers(code));
} }
void functionpointer4() {
const char code[] = ""
"struct S\n"
"{\n"
" typedef void (*FP)();\n"
" virtual FP getFP();\n"
" virtual void execute();\n"
"};\n"
"void f() {\n"
" int a[9];\n"
"}\n";
const char expected[] = "\n\n##file 0\n"
"1: struct S\n"
"2: {\n"
"3: ;\n"
"4: virtual void ( * getFP ( ) ) ( ) ;\n"
"5: virtual void execute ( ) ;\n"
"6: } ;\n"
"7: void f ( ) {\n"
"8: int a@1 [ 9 ] ;\n"
"9: }\n";
ASSERT_EQUALS(expected, tokenizeDebugListing(code, false));
}
void removeRedundantAssignment() { void removeRedundantAssignment() {
ASSERT_EQUALS("void f ( ) { ; int * q ; }", tokenizeAndStringify("void f() { int *p, *q; p = q; }", true)); ASSERT_EQUALS("void f ( ) { ; int * q ; }", tokenizeAndStringify("void f() { int *p, *q; p = q; }", true));
ASSERT_EQUALS("void f ( ) { ; int * q ; }", tokenizeAndStringify("void f() { int *p = 0, *q; p = q; }", true)); ASSERT_EQUALS("void f ( ) { ; int * q ; }", tokenizeAndStringify("void f() { int *p = 0, *q; p = q; }", true));