Fixed simplification of pointers (#6829)
This commit is contained in:
parent
6336372fb4
commit
feae241fc0
|
@ -6757,7 +6757,8 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
|||
tok3 = tok3->previous();
|
||||
tok3->deleteThis();
|
||||
ret = true;
|
||||
}
|
||||
} else if (Token::Match(valueToken, "& %name% ;"))
|
||||
tok3->insertToken("&", true);
|
||||
}
|
||||
|
||||
if (Token::simpleMatch(tok3, "= {")) {
|
||||
|
|
|
@ -181,6 +181,7 @@ private:
|
|||
TEST_CASE(simplifyKnownVariables57); // ticket #4724
|
||||
TEST_CASE(simplifyKnownVariables58); // ticket #5268
|
||||
TEST_CASE(simplifyKnownVariables59); // skip for header
|
||||
TEST_CASE(simplifyKnownVariables60); // #6829
|
||||
TEST_CASE(simplifyKnownVariablesBailOutAssign1);
|
||||
TEST_CASE(simplifyKnownVariablesBailOutAssign2);
|
||||
TEST_CASE(simplifyKnownVariablesBailOutAssign3); // #4395 - nested assignments
|
||||
|
@ -2675,6 +2676,21 @@ private:
|
|||
"}", tokenizeAndStringify(code, true));
|
||||
}
|
||||
|
||||
void simplifyKnownVariables60() { // #6829
|
||||
const char code[] = "void f() {\n"
|
||||
" int i = 1;\n"
|
||||
" const int * const constPtrToConst = &i;\n"
|
||||
" std::cout << *constPtrToConst << std::endl;\n"
|
||||
" std::cout << constPtrToConst << std::endl;\n"
|
||||
"}";
|
||||
ASSERT_EQUALS("void f ( ) {\n"
|
||||
"int i ; i = 1 ;\n"
|
||||
"const int * constPtrToConst ; constPtrToConst = & i ;\n"
|
||||
"std :: cout << i << std :: endl ;\n"
|
||||
"std :: cout << & i << std :: endl ;\n"
|
||||
"}", tokenizeAndStringify(code, true));
|
||||
}
|
||||
|
||||
void simplifyKnownVariablesBailOutAssign1() {
|
||||
const char code[] = "int foo() {\n"
|
||||
" int i; i = 0;\n"
|
||||
|
|
Loading…
Reference in New Issue