Fix faulty removal of parenthesis when "]" is followed by parenthesis with a number inside, for example when calling a function pointer in an array or (perhaps more common) in c++, calling operator ( on an element in an array. Fixes #8875 where such wrong simplification lead to a FP with too many bits shifted due to "<<" was interpreted like a shift operator rather than a stream output.
This commit is contained in:
parent
f1eccc8d63
commit
103e52f394
|
@ -8741,11 +8741,11 @@ bool Tokenizer::simplifyRedundantParentheses()
|
|||
ret = true;
|
||||
}
|
||||
|
||||
// Simplify "!!operator !!%name%|)|>|>> ( %num%|%bool% ) %op%|;|,|)"
|
||||
// Simplify "!!operator !!%name%|)|]|>|>> ( %num%|%bool% ) %op%|;|,|)"
|
||||
if (Token::Match(tok, "( %bool%|%num% ) %cop%|;|,|)") &&
|
||||
tok->strAt(-2) != "operator" &&
|
||||
tok->previous() &&
|
||||
!Token::Match(tok->previous(), "%name%|)") &&
|
||||
!Token::Match(tok->previous(), "%name%|)|]") &&
|
||||
(!(isCPP() && Token::Match(tok->previous(),">|>>")))) {
|
||||
tok->link()->deleteThis();
|
||||
tok->deleteThis();
|
||||
|
|
|
@ -171,6 +171,7 @@ private:
|
|||
TEST_CASE(removeParentheses23); // Ticket #6103 - Infinite loop upon valid input
|
||||
TEST_CASE(removeParentheses24); // Ticket #7040
|
||||
TEST_CASE(removeParentheses25); // daca@home - a=(b,c)
|
||||
TEST_CASE(removeParentheses26); // Ticket #8875 a[0](0)
|
||||
|
||||
TEST_CASE(tokenize_double);
|
||||
TEST_CASE(tokenize_strings);
|
||||
|
@ -1676,6 +1677,12 @@ private:
|
|||
ASSERT_EQUALS(exp, tokenizeAndStringify(code));
|
||||
}
|
||||
|
||||
void removeParentheses26() { // Ticket #8875 a[0](0)
|
||||
static char code[] = "a[0](0);";
|
||||
static char exp[] = "a [ 0 ] ( 0 ) ;";
|
||||
ASSERT_EQUALS(exp, tokenizeAndStringify(code));
|
||||
}
|
||||
|
||||
void tokenize_double() {
|
||||
const char code[] = "void f() {\n"
|
||||
" double a = 4.2;\n"
|
||||
|
|
|
@ -204,6 +204,12 @@ private:
|
|||
" return -(y << (x-1));\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("bool f() {\n"
|
||||
" std::ofstream outfile;\n"
|
||||
" outfile << vec_points[0](0) << static_cast<int>(d) << ' ';\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void checkIntegerOverflow() {
|
||||
|
|
Loading…
Reference in New Issue