From 34e40502c68739394ca9ea2c31479245c717e415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 11 Nov 2011 10:53:49 +0100 Subject: [PATCH] Fixed #3314 (cppcheck incorrectly reporting Syntax error.) --- lib/tokenize.cpp | 8 ++++++++ test/testtokenize.cpp | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 990ab433a..bbbadbb76 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1097,6 +1097,14 @@ void Tokenizer::simplifyTypedef() continue; } + // unhandled function pointer, skip it and continue + else if (Token::Match(tok->tokAt(offset), "( %type% ::") && + Token::Match(tok->tokAt(offset)->link()->tokAt(-3), ":: * %var% ) (")) { + unsupportedTypedef(typeDef); + tok = deleteInvalidTypedef(typeDef); + continue; + } + // function pointer else if (Token::Match(tok->tokAt(offset), "( * %var% ) (")) { // name token wasn't a name, it was part of the type diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index bdab56cbb..70f53dcc8 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -610,6 +610,14 @@ private: tokenizeAndStringify(code.c_str(), true); ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); } + + { + // #3314 - don't report syntax error. + errout.str(""); + const std::string code("struct A { typedef B::C (A::*f)(); };"); + tokenizeAndStringify(code.c_str(), true); + ASSERT_EQUALS("[test.cpp:1]: (debug) Failed to parse 'typedef B :: C ( A :: * f ) ( ) ;'. The checking continues anyway.\n", errout.str()); + } } void wrong_syntax_if_macro() {