Tokenizer: Better handling of c alternative tokens in const method

This commit is contained in:
Daniel Marjamäki 2020-05-25 15:07:23 +02:00
parent f7bff1a272
commit f7f26ffe90
2 changed files with 10 additions and 1 deletions

View File

@ -7093,8 +7093,16 @@ bool Tokenizer::simplifyCAlternativeTokens()
bool ret = false;
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (tok->str() == ")") {
if (const Token *end = isFunctionHead(tok, "{")) {
++executableScopeLevel;
tok = const_cast<Token *>(end);
continue;
}
}
if (tok->str() == "{") {
if (executableScopeLevel > 0 || Token::simpleMatch(tok->previous(), ") {"))
if (executableScopeLevel > 0)
++executableScopeLevel;
continue;
}

View File

@ -6183,6 +6183,7 @@ private:
ASSERT_EQUALS("void f ( ) { if ( ~ b ) { ; } }", tokenizeAndStringify("void f() { if (compl b); }", false, true, Settings::Native, "test.cpp"));
ASSERT_EQUALS("void f ( ) { if ( ! b ) { ; } }", tokenizeAndStringify("void f() { if (not b); }", false, true, Settings::Native, "test.c"));
ASSERT_EQUALS("void f ( ) { if ( ! b ) { ; } }", tokenizeAndStringify("void f() { if (not b); }", false, true, Settings::Native, "test.cpp"));
ASSERT_EQUALS("void f ( ) const { if ( ! b ) { ; } }", tokenizeAndStringify("void f() const { if (not b); }", false, true, Settings::Native, "test.cpp"));
ASSERT_EQUALS("void f ( ) { if ( a != b ) { ; } }", tokenizeAndStringify("void f() { if (a not_eq b); }", false, true, Settings::Native, "test.c"));
ASSERT_EQUALS("void f ( ) { if ( a != b ) { ; } }", tokenizeAndStringify("void f() { if (a not_eq b); }", false, true, Settings::Native, "test.cpp"));
// #6201