fix syntax error for num.operator std::string()[0] (#2389)

This commit is contained in:
IOBYTE 2019-11-23 11:42:24 -05:00 committed by Daniel Marjamäki
parent 14469aced8
commit fb1d60bfb1
2 changed files with 12 additions and 2 deletions

View File

@ -95,8 +95,11 @@ const Token * Tokenizer::isFunctionHead(const Token *tok, const std::string &end
tok = tok->link();
if (Token::Match(tok, ") ;|{|[")) {
tok = tok->next();
while (tok && tok->str() == "[" && tok->link())
while (tok && tok->str() == "[" && tok->link()) {
if (endsWith.find(tok->str()) != std::string::npos)
return tok;
tok = tok->link()->next();
}
return (tok && endsWith.find(tok->str()) != std::string::npos) ? tok : nullptr;
}
if (cpp && tok->str() == ")") {
@ -10815,7 +10818,7 @@ void Tokenizer::deleteSymbolDatabase()
bool Tokenizer::operatorEnd(const Token * tok) const
{
if (tok && tok->str() == ")") {
if (isFunctionHead(tok, "{|;|?|:"))
if (isFunctionHead(tok, "{|;|?|:|["))
return true;
tok = tok->next();

View File

@ -409,6 +409,7 @@ private:
TEST_CASE(simplifyOperatorName22);
TEST_CASE(simplifyOperatorName23);
TEST_CASE(simplifyOperatorName24);
TEST_CASE(simplifyOperatorName25);
TEST_CASE(simplifyNullArray);
@ -6561,6 +6562,12 @@ private:
}
}
void simplifyOperatorName25() {
const char code[] = "bool negative(const Number &num) { return num.operator std::string()[0] == '-'; }";
ASSERT_EQUALS("bool negative ( const Number & num ) { return num . operatorstd::string ( ) [ 0 ] == '-' ; }",
tokenizeAndStringify(code));
}
void simplifyNullArray() {
ASSERT_EQUALS("* ( foo . bar [ 5 ] ) = x ;", tokenizeAndStringify("0[foo.bar[5]] = x;"));
}