Fixed #5131 (False Positive: %u in format string requires 'unsigned int' but the argument type is 'int'.)
This commit is contained in:
parent
352c459e28
commit
d3bd373798
|
@ -6075,18 +6075,14 @@ void Tokenizer::simplifyInitVar()
|
|||
while (tok1->str() != ",")
|
||||
tok1 = tok1->next();
|
||||
tok1->str(";");
|
||||
Token *tok2 = tok;
|
||||
unsigned int num = 0;
|
||||
const Token *tok2 = tok;
|
||||
if (Token::Match(tok2, "class|struct|union")) {
|
||||
tok1->insertToken(tok2->str());
|
||||
tok1 = tok1->next();
|
||||
num++;
|
||||
tok2 = tok2->next();
|
||||
}
|
||||
tok1->insertToken(tok2->str());
|
||||
tok1 = tok1->next();
|
||||
tok2 = tok2->next();
|
||||
if (tok2->str() == "*") {
|
||||
tok1->insertToken("*");
|
||||
}
|
||||
num++;
|
||||
list.insertTokens(tok1, tok, num);
|
||||
tok = initVar(tok);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -432,6 +432,8 @@ private:
|
|||
|
||||
TEST_CASE(labels);
|
||||
TEST_CASE(simplifyInitVar);
|
||||
TEST_CASE(simplifyInitVar2);
|
||||
TEST_CASE(simplifyInitVar3);
|
||||
|
||||
TEST_CASE(bitfields1);
|
||||
TEST_CASE(bitfields2);
|
||||
|
@ -7136,6 +7138,25 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
void simplifyInitVar2() {
|
||||
// ticket #5131 - unsigned
|
||||
const char code[] = "void f() {\n"
|
||||
" unsigned int a(0),b(0);\n"
|
||||
"}";
|
||||
ASSERT_EQUALS("void f ( ) {\n"
|
||||
"unsigned int a ; a = 0 ; unsigned int b ; b = 0 ;\n"
|
||||
"}", tokenizeAndStringify(code));
|
||||
}
|
||||
|
||||
void simplifyInitVar3() {
|
||||
const char code[] = "void f() {\n"
|
||||
" int *a(0),b(0);\n"
|
||||
"}";
|
||||
ASSERT_EQUALS("void f ( ) {\n"
|
||||
"int * a ; a = 0 ; int b ; b = 0 ;\n"
|
||||
"}", tokenizeAndStringify(code));
|
||||
}
|
||||
|
||||
void bitfields1() {
|
||||
const char code1[] = "struct A { bool x : 1; };";
|
||||
ASSERT_EQUALS("struct A { bool x ; } ;", tokenizeAndStringify(code1,false));
|
||||
|
|
Loading…
Reference in New Issue