fix syntax error for num.operator std::string()[0] (#2389)
This commit is contained in:
parent
14469aced8
commit
fb1d60bfb1
|
@ -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();
|
||||
|
|
|
@ -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;"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue