diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 18fa83df9..099a5280c 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3604,22 +3604,22 @@ Function * SymbolDatabase::findFunctionInScope(const Token *func, const Scope *n bool SymbolDatabase::isReservedName(const std::string& iName) const { static const std::set c_keywords = make_container>() << - "auto" << "break" << "case" << "char" << "const" << "continue" << "default" << "do" << - "double" << "else" << "enum" << "extern" << "float" << "for" << "goto" << "if" << "inline" << - "int" << "long" << "register" << "restrict" << "return" << "short" << "signed" << "sizeof" << - "static" << "struct" << "switch" << "typedef" << "union" << "unsigned" << "void" << "volatile" << - "while"; + "auto" << "break" << "case" << "char" << "const" << "continue" << "default" << "do" << + "double" << "else" << "enum" << "extern" << "float" << "for" << "goto" << "if" << "inline" << + "int" << "long" << "register" << "restrict" << "return" << "short" << "signed" << "sizeof" << + "static" << "struct" << "switch" << "typedef" << "union" << "unsigned" << "void" << "volatile" << + "while"; static const std::set cpp_keywords = make_container>() << - "alignas" << "alignof" << "and" << "and_eq" << "asm" << "auto" << "bitand" << "bitor" << "bool" << - "break" << "case" << "catch" << "char" << "char16_t" << "char32_t" << "class" << "compl" << - "concept" << "const" << "constexpr" << "const_cast" << "continue" << "decltype" << "default" << - "delete" << "do" << "double" << "dynamic_cast" << "else" << "enum" << "explicit" << "export" << - "extern" << "false" << "float" << "for" << "friend" << "goto" << "if" << "inline" << "int" << "long" << - "mutable" << "namespace" << "new" << "noexcept" << "not" << "not_eq" << "nullptr" << "operator" << - "or" << "or_eq" << "private" << "protected" << "public" << "register" << "reinterpret_cast" << - "requires" << "return" << "short" << "signed" << "sizeof" << "static" << "static_assert" << - "static_cast" << "struct" << "switch" << "template" << "this" << "thread_local" << "throw" << - "true" << "try" << "typedef" << "typeid" << "typename" << "union" << "unsigned" << "using" << - "virtual" << "void" << "volatile" << "wchar_t" << "while" << "xor" << "xor_eq"; + "alignas" << "alignof" << "and" << "and_eq" << "asm" << "auto" << "bitand" << "bitor" << "bool" << + "break" << "case" << "catch" << "char" << "char16_t" << "char32_t" << "class" << "compl" << + "concept" << "const" << "constexpr" << "const_cast" << "continue" << "decltype" << "default" << + "delete" << "do" << "double" << "dynamic_cast" << "else" << "enum" << "explicit" << "export" << + "extern" << "false" << "float" << "for" << "friend" << "goto" << "if" << "inline" << "int" << "long" << + "mutable" << "namespace" << "new" << "noexcept" << "not" << "not_eq" << "nullptr" << "operator" << + "or" << "or_eq" << "private" << "protected" << "public" << "register" << "reinterpret_cast" << + "requires" << "return" << "short" << "signed" << "sizeof" << "static" << "static_assert" << + "static_cast" << "struct" << "switch" << "template" << "this" << "thread_local" << "throw" << + "true" << "try" << "typedef" << "typeid" << "typename" << "union" << "unsigned" << "using" << + "virtual" << "void" << "volatile" << "wchar_t" << "while" << "xor" << "xor_eq"; return (c_keywords.find(iName) != c_keywords.cend()) || (isCPP() && (cpp_keywords.find(iName) != cpp_keywords.cend())); } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index badf2622a..345523e00 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9308,7 +9308,7 @@ void Tokenizer::simplifyKeyword() } } - if (_settings->standards.cpp >= Standards::CPP11) { + if (isCPP() && _settings->standards.cpp >= Standards::CPP11) { for (Token *tok = list.front(); tok; tok = tok->next()) { while (tok->str() == "constexpr") { tok->deleteThis(); @@ -9327,12 +9327,17 @@ void Tokenizer::simplifyKeyword() //if (Token::Match(tok, ") override [{;]")) if (Token::Match(tok, ") const|override|final")) { Token* specifier = tok->tokAt(2); - while (specifier && Token::Match(specifier, "const|override|final")) + while (specifier && Token::Match(specifier, "const|override|final")) { specifier=specifier->next(); + } if (specifier && Token::Match(specifier, "[{;]")) { - specifier=tok->next(); - while (specifier->str()=="override" || specifier->str()=="final") - specifier->deleteThis(); + specifier = tok->next(); + while (!Token::Match(specifier, "[{;]")) { + if (specifier->str()=="const") + specifier=specifier->next(); + else + specifier->deleteThis(); + } } } } diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 97e4cb0d4..70f15de8b 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -1195,7 +1195,7 @@ private: " HeapDestroy(MyHeap);" "}"); TODO_ASSERT_EQUALS("", "[test.c:1]: (error) Mismatching allocation and deallocation: MyHeap\n" - "[test.c:1]: (error) Resource handle 'MyHeap' freed twice.\n", errout.str()); + "[test.c:1]: (error) Resource handle 'MyHeap' freed twice.\n", errout.str()); check("void f() {" " int *a = HeapAlloc(GetProcessHeap(), 0, sizeof(int));" @@ -1213,7 +1213,7 @@ private: " HeapDestroy(MyHeap);" "}"); TODO_ASSERT_EQUALS("[test.c:1] (error) Memory leak: b", "[test.c:1]: (error) Mismatching allocation and deallocation: MyHeap\n" - "[test.c:1]: (error) Memory leak: b\n", errout.str()); + "[test.c:1]: (error) Memory leak: b\n", errout.str()); check("void f() {" " HANDLE MyHeap = HeapCreate(0, 0, 0);" diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index c1f618fc3..906f0878a 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4485,6 +4485,24 @@ private: const char in4 [] = "struct B final : A { void foo(); };"; const char out4 [] = "struct B : A { void foo ( ) ; } ;"; ASSERT_EQUALS(out4, tokenizeAndStringify(in4)); + + const char in5 [] = "struct ArrayItemsValidator final {\n" + " SchemaError validate() const override {\n" + " for (; pos < value.size(); ++pos) {\n" + " }\n" + " return none;\n" + " }\n" + "};\n"; + const char out5 [] = + "struct ArrayItemsValidator {\n" + "SchemaError validate ( ) const {\n" + "for ( ; pos < value . size ( ) ; ++ pos ) {\n" + "}\n" + "return none ;\n" + "}\n" + "} ;"; + + ASSERT_EQUALS(out5, tokenizeAndStringify(in5)); } }