From 954371e3f8b70e0791286659919d193d0bcc472b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 23 Nov 2008 14:21:37 +0000 Subject: [PATCH] Function usage: Handling callbacks better: 'void (*f)() = cond ? foo : NULL' --- CheckFunctionUsage.cpp | 2 +- testfunctionusage.cpp | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CheckFunctionUsage.cpp b/CheckFunctionUsage.cpp index 8c6745250..3c5b1dcc6 100644 --- a/CheckFunctionUsage.cpp +++ b/CheckFunctionUsage.cpp @@ -91,7 +91,7 @@ void CheckFunctionUsage::parseTokens( const Tokenizer &tokenizer ) { const TOKEN *funcname = 0; - if ( TOKEN::Match( tok, "[;{}.,()[=+-/&|] %var% [(),;]" ) || + if ( TOKEN::Match( tok, "[;{}.,()[=+-/&|?:] %var% [(),;:]" ) || TOKEN::Match(tok, ":: %var% (") || TOKEN::Match(tok, "|= %var% (") || TOKEN::Match(tok, "&= %var% (") || diff --git a/testfunctionusage.cpp b/testfunctionusage.cpp index 4e6ad8dbd..b80c94482 100644 --- a/testfunctionusage.cpp +++ b/testfunctionusage.cpp @@ -37,7 +37,8 @@ private: void run() { TEST_CASE( incondition ); - TEST_CASE( return1 ); + TEST_CASE( return1 ); + TEST_CASE( callback1 ); } void check( const char code[] ) @@ -76,6 +77,16 @@ private: "}\n" ); std::string err( errout.str() ); ASSERT_EQUALS( std::string(""), errout.str() ); + } + + void callback1() + { + check( "void f1()\n" + "{\n" + " void (*f)() = cond ? f1 : NULL;\n" + "}\n" ); + std::string err( errout.str() ); + ASSERT_EQUALS( std::string(""), errout.str() ); } };