diff --git a/testtokenize.cpp b/testtokenize.cpp index 4b454f404..905d4db07 100644 --- a/testtokenize.cpp +++ b/testtokenize.cpp @@ -42,7 +42,9 @@ private: TEST_CASE( inlineasm ); - TEST_CASE( dupfuncname ); + TEST_CASE( dupfuncname ); + + TEST_CASE( const_and_volatile_functions ); } @@ -146,6 +148,42 @@ private: ASSERT_EQUALS( 1, tokenizer._functionList.size() ); ASSERT_EQUALS( std::string("b"), tokenizer._functionList[0]->aaaa() ); + } + + void const_and_volatile_functions() + { + const char code[] = "class B\n\ + {\n\ + public:\n\ + void a();\n\ + void b() const;\n\ + void c() volatile;\n\ + };\n\ + \n\ + void B::a()\n\ + {}\n\ + \n\ + void B::b() const\n\ + {}\n\ + \n\ + void B::c() volatile\n\ + {}\n"; + + + // tokenize.. + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + + tokenizer.fillFunctionList(); + + ASSERT_EQUALS( 3, tokenizer._functionList.size() ); + if( tokenizer._functionList.size() == 3 ) + { + ASSERT_EQUALS( std::string("a"), tokenizer._functionList[0]->aaaa() ); + ASSERT_EQUALS( std::string("b"), tokenizer._functionList[1]->aaaa() ); + ASSERT_EQUALS( std::string("c"), tokenizer._functionList[2]->aaaa() ); + } } }; diff --git a/tokenize.cpp b/tokenize.cpp index eed118505..71da7e703 100644 --- a/tokenize.cpp +++ b/tokenize.cpp @@ -1084,6 +1084,16 @@ void Tokenizer::fillFunctionList() { _functionList.push_back( tok ); tok = tok2; + } + else if ( TOKEN::Match(tok2, ") const {") ) + { + _functionList.push_back( tok ); + tok = tok2; + } + else if ( TOKEN::Match(tok2, ") volatile {") ) + { + _functionList.push_back( tok ); + tok = tok2; } else { @@ -1100,7 +1110,7 @@ void Tokenizer::fillFunctionList() // If the _functionList functions with duplicate names, remove them // TODO this will need some better handling for ( unsigned int func1 = 0; func1 < _functionList.size(); ) - { + { bool hasDuplicates = false; for ( unsigned int func2 = func1 + 1; func2 < _functionList.size(); ) { @@ -1123,7 +1133,7 @@ void Tokenizer::fillFunctionList() { _functionList.erase( _functionList.begin() + func1 ); } - } + } } //---------------------------------------------------------------------------