Fix 10951: FP knownEmptyContainer with east-const (#3988)

* Fix 10951: FP knownEmptyContainer with east-const

* Format

* Use simpleMatch
This commit is contained in:
Paul Fultz II 2022-04-08 01:22:39 -05:00 committed by GitHub
parent ceb86afc22
commit d2a0b0f78e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 3 deletions

View File

@ -7494,6 +7494,10 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
++typelen;
tok2 = tok2->next();
}
// east const
if (Token::simpleMatch(tok2, "const"))
isconst = true;
}
//pattern: "%type% *| ... *| const| %name% ,|="
@ -7672,6 +7676,13 @@ void Tokenizer::simplifyStaticConst()
}
if (behindOther)
break;
if (isCPP() && Token::simpleMatch(leftTok, ">")) {
Token* opening = leftTok->findOpeningBracket();
if (opening) {
leftTok = opening;
continue;
}
}
if (!Token::Match(leftTok, "%type%|struct|::") ||
(isCPP() && Token::Match(leftTok, "private:|protected:|public:|operator|template"))) {
break;

View File

@ -4142,7 +4142,7 @@ private:
void simplifyOperator2() {
// #6576
ASSERT_EQUALS("template < class T > class SharedPtr { "
"SharedPtr & operator= ( SharedPtr < Y > const & r ) ; "
"SharedPtr & operator= ( const SharedPtr < Y > & r ) ; "
"} ; "
"class TClass { "
"public: TClass & operator= ( const TClass & rhs ) ; "

View File

@ -1391,7 +1391,7 @@ private:
"I i;";
// The expected result..
const char expected[] = "std :: pair < int , int > const i ;";
const char expected[] = "const std :: pair < int , int > i ;";
ASSERT_EQUALS(expected, tok(code));
}

View File

@ -222,6 +222,7 @@ private:
TEST_CASE(vardecl28);
TEST_CASE(vardecl_stl_1);
TEST_CASE(vardecl_stl_2);
TEST_CASE(vardecl_stl_3);
TEST_CASE(vardecl_template_1);
TEST_CASE(vardecl_template_2);
TEST_CASE(vardecl_union);
@ -2075,6 +2076,15 @@ private:
ASSERT_EQUALS("{ std :: vector < int > x ; x = y ; }", tokenizeAndStringify(code2));
}
void vardecl_stl_3()
{
const char code1[] = "{ std::string const x = \"abc\"; }";
ASSERT_EQUALS("{ const std :: string x = \"abc\" ; }", tokenizeAndStringify(code1));
const char code2[] = "{ std::vector<int> const x = y; }";
ASSERT_EQUALS("{ const std :: vector < int > x = y ; }", tokenizeAndStringify(code2));
}
void vardecl_template_1() {
// ticket #1046
const char code1[] = "b<(1<<24),10,24> u, v;";

View File

@ -1165,7 +1165,7 @@ private:
void varid63() {
const char code[] = "void f(boost::optional<int> const& x) {}";
const char expected[] = "1: void f ( boost :: optional < int > const & x@1 ) { }\n";
const char expected[] = "1: void f ( const boost :: optional < int > & x@1 ) { }\n";
ASSERT_EQUALS(expected, tokenize(code));
}