diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 641773862..75f28fc62 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8046,6 +8046,14 @@ void Tokenizer::validateC() const if (!isC()) return; for (const Token *tok = tokens(); tok; tok = tok->next()) { + // Template function.. + if (Token::Match(tok, "%name% < %name% > (")) { + const Token *tok2 = tok->tokAt(5); + while (tok2 && !Token::Match(tok2, "[()]")) + tok2 = tok2->next(); + if (Token::simpleMatch(tok2, ") {")) + syntaxErrorC(tok, tok->str() + '<' + tok->strAt(2) + ">() {}"); + } if (tok->previous() && !Token::Match(tok->previous(), "[;{}]")) continue; if (Token::simpleMatch(tok, "using namespace std ;")) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index c0e337e88..687c274ff 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -790,6 +790,7 @@ private: ASSERT_THROW(tokenizeAndStringify(";using namespace std;",false,false,Settings::Native,"test.c"), InternalError); ASSERT_THROW(tokenizeAndStringify(";std::map m;",false,false,Settings::Native,"test.c"), InternalError); ASSERT_THROW(tokenizeAndStringify(";template class X { };",false,false,Settings::Native,"test.c"), InternalError); + ASSERT_THROW(tokenizeAndStringify("int X() {};",false,false,Settings::Native,"test.c"), InternalError); } void syntax_case_default() { // correct syntax