fix #10295 (false negatives by inconsistent 'void' in argument list (declaration vs definition)) (#3274)

Co-authored-by: Robert Reif <reif@FX6840>
This commit is contained in:
Robert Reif 2021-05-24 13:32:15 -04:00 committed by GitHub
parent d3bb84cd0e
commit c7be967769
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 0 deletions

View File

@ -2429,6 +2429,11 @@ bool Function::argsMatch(const Scope *scope, const Token *first, const Token *se
int offset = 0; int offset = 0;
int openParen = 0; int openParen = 0;
// check for () == (void) and (void) == ()
if ((Token::simpleMatch(first, "( )") && Token::simpleMatch(second, "( void )")) ||
(Token::simpleMatch(first, "( void )") && Token::simpleMatch(second, "( )")))
return true;
while (first->str() == second->str() && while (first->str() == second->str() &&
first->isLong() == second->isLong() && first->isLong() == second->isLong() &&
first->isUnsigned() == second->isUnsigned()) { first->isUnsigned() == second->isUnsigned()) {

View File

@ -148,6 +148,7 @@ private:
TEST_CASE(uninitVar30); // ticket #6417 TEST_CASE(uninitVar30); // ticket #6417
TEST_CASE(uninitVar31); // ticket #8271 TEST_CASE(uninitVar31); // ticket #8271
TEST_CASE(uninitVar32); // ticket #8835 TEST_CASE(uninitVar32); // ticket #8835
TEST_CASE(uninitVar33); // ticket #10295
TEST_CASE(uninitVarEnum1); TEST_CASE(uninitVarEnum1);
TEST_CASE(uninitVarEnum2); // ticket #8146 TEST_CASE(uninitVarEnum2); // ticket #8146
TEST_CASE(uninitVarStream); TEST_CASE(uninitVarStream);
@ -2524,6 +2525,18 @@ private:
ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Foo::member' is not initialized in the constructor.\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Foo::member' is not initialized in the constructor.\n", errout.str());
} }
void uninitVar33() { // ticket #10295
check("namespace app {\n"
" class B {\n"
" public:\n"
" B(void);\n"
" int x;\n"
" };\n"
"};\n"
"app::B::B(void){}");
ASSERT_EQUALS("[test.cpp:8]: (warning) Member variable 'B::x' is not initialized in the constructor.\n", errout.str());
}
void uninitVarArray1() { void uninitVarArray1() {
check("class John\n" check("class John\n"
"{\n" "{\n"

View File

@ -347,6 +347,7 @@ private:
TEST_CASE(symboldatabase92); // daca crash TEST_CASE(symboldatabase92); // daca crash
TEST_CASE(symboldatabase93); // alignas attribute TEST_CASE(symboldatabase93); // alignas attribute
TEST_CASE(symboldatabase94); // structured bindings TEST_CASE(symboldatabase94); // structured bindings
TEST_CASE(symboldatabase95); // #10295
TEST_CASE(createSymbolDatabaseFindAllScopes1); TEST_CASE(createSymbolDatabaseFindAllScopes1);
@ -4720,6 +4721,24 @@ private:
ASSERT(db->getVariableFromVarId(2) != nullptr); ASSERT(db->getVariableFromVarId(2) != nullptr);
} }
void symboldatabase95() { // #10295
GET_SYMBOL_DB("struct B {\n"
" void foo1(void);\n"
" void foo2();\n"
"};\n"
"void B::foo1() {}\n"
"void B::foo2(void) {}\n");
ASSERT_EQUALS("", errout.str());
const Token *functok = Token::findsimplematch(tokenizer.tokens(), "foo1 ( ) { }");
ASSERT(functok);
ASSERT(functok->function());
ASSERT(functok->function()->name() == "foo1");
functok = Token::findsimplematch(tokenizer.tokens(), "foo2 ( void ) { }");
ASSERT(functok);
ASSERT(functok->function());
ASSERT(functok->function()->name() == "foo2");
}
void createSymbolDatabaseFindAllScopes1() { void createSymbolDatabaseFindAllScopes1() {
GET_SYMBOL_DB("void f() { union {int x; char *p;} a={0}; }"); GET_SYMBOL_DB("void f() { union {int x; char *p;} a={0}; }");
ASSERT(db->scopeList.size() == 3); ASSERT(db->scopeList.size() == 3);