From f56aa19fac101b9ec6f90b50cc6e1d65d2af149a Mon Sep 17 00:00:00 2001 From: Richard Quirk Date: Wed, 9 Nov 2011 21:02:41 +0100 Subject: [PATCH] Fix varid 0 with function pointer and virtual methods --- lib/tokenize.cpp | 3 +++ test/testtokenize.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2697bc887..990ab433a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3373,6 +3373,9 @@ void Tokenizer::setVarId() if (tok->str() == "throw") continue; + if (tok->str() == "virtual") + continue; + if (tok->str() == "unsigned") tok = tok->next(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index e42794bcb..b49e96901 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -300,6 +300,7 @@ private: TEST_CASE(functionpointer1); TEST_CASE(functionpointer2); TEST_CASE(functionpointer3); + TEST_CASE(functionpointer4); TEST_CASE(removeRedundantAssignment); @@ -4872,6 +4873,30 @@ private: 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() { 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));