Skip to content

Commit 44ce2eb

Browse files
committed
Fix struct typescope for C code in dumpfile
1 parent 996faff commit 44ce2eb

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

lib/symboldatabase.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6571,23 +6571,6 @@ const Type* SymbolDatabase::findType(const Token *startTok, const Scope *startSc
65716571
if (startTok->str() == startScope->className && startScope->isClassOrStruct() && startTok->strAt(1) != "::")
65726572
return startScope->definedType;
65736573

6574-
if (startTok->isC()) {
6575-
const Scope* scope = startScope;
6576-
while (scope) {
6577-
if (startTok->str() == scope->className && scope->isClassOrStruct())
6578-
return scope->definedType;
6579-
const Scope* typeScope = scope->findRecordInNestedList(startTok->str(), /*isC*/ true);
6580-
if (typeScope) {
6581-
if (startTok->str() == typeScope->className && typeScope->isClassOrStruct()) {
6582-
if (const Type* type = typeScope->definedType)
6583-
return type;
6584-
}
6585-
}
6586-
scope = scope->nestedIn;
6587-
}
6588-
return nullptr;
6589-
}
6590-
65916574
const Scope* start_scope = startScope;
65926575

65936576
// absolute path - directly start in global scope

test/cfg/gtk.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ void g_new_if_test()
292292
};
293293

294294
const struct a * pNew3;
295-
// cppcheck-suppress valueFlowBailoutIncompleteVar
296295
if (pNew3 = g_new(struct a, 6)) {
297296
printf("%p", pNew3);
298297
}
@@ -305,7 +304,6 @@ void g_new0_test()
305304
int b;
306305
};
307306
// valid
308-
// cppcheck-suppress valueFlowBailoutIncompleteVar
309307
struct a * pNew1 = g_new0(struct a, 5);
310308
printf("%p", pNew1);
311309
g_free(pNew1);
@@ -324,7 +322,6 @@ void g_try_new_test()
324322
int b;
325323
};
326324
// valid
327-
// cppcheck-suppress valueFlowBailoutIncompleteVar
328325
struct a * pNew1 = g_try_new(struct a, 5);
329326
printf("%p", pNew1);
330327
g_free(pNew1);
@@ -342,7 +339,6 @@ void g_try_new0_test()
342339
int b;
343340
};
344341
// valid
345-
// cppcheck-suppress valueFlowBailoutIncompleteVar
346342
struct a * pNew1 = g_try_new0(struct a, 5);
347343
printf("%p", pNew1);
348344
g_free(pNew1);
@@ -360,7 +356,7 @@ void g_renew_test()
360356
struct a {
361357
int b;
362358
};
363-
// cppcheck-suppress [leakReturnValNotUsed,valueFlowBailoutIncompleteVar]
359+
// cppcheck-suppress leakReturnValNotUsed
364360
g_renew(struct a, NULL, 1);
365361

366362
struct a * pNew = g_new(struct a, 1);
@@ -375,7 +371,7 @@ void g_try_renew_test()
375371
struct a {
376372
int b;
377373
};
378-
// cppcheck-suppress [leakReturnValNotUsed,valueFlowBailoutIncompleteVar]
374+
// cppcheck-suppress leakReturnValNotUsed
379375
g_try_renew(struct a, NULL, 1);
380376

381377
struct a * pNew = g_try_new(struct a, 1);

test/testsymboldatabase.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ class TestSymbolDatabase : public TestFixture {
619619
TEST_CASE(incomplete_type); // #9255 (infinite recursion)
620620
TEST_CASE(exprIds);
621621
TEST_CASE(testValuetypeOriginalName);
622+
TEST_CASE(testValueTypeTypeScope);
622623

623624
TEST_CASE(dumpFriend); // Check if isFriend added to dump file
624625

@@ -11318,6 +11319,28 @@ class TestSymbolDatabase : public TestFixture {
1131811319
}
1131911320
}
1132011321

11322+
void testValueTypeTypeScope() {
11323+
GET_SYMBOL_DB_C("struct deer {\n"
11324+
" uint16_t a;\n"
11325+
" uint16_t b;\n"
11326+
"};\n"
11327+
"void herd ( void ) {\n"
11328+
" struct deer {\n"
11329+
" uint16_t a;\n"
11330+
" };\n"
11331+
"}");
11332+
11333+
ASSERT_EQUALS("", errout_str());
11334+
11335+
const Token* f = Token::findsimplematch(tokenizer.tokens(), "struct deer {");
11336+
ASSERT(db && f && f->tokAt(2) && f->tokAt(2)->valueType());
11337+
ASSERT_EQUALS(f->tokAt(2)->scope(), f->tokAt(2)->valueType()->typeScope);
11338+
11339+
f = Token::findsimplematch(tokenizer.tokens(), "{ struct deer {");
11340+
ASSERT(f && f->tokAt(3) && f->tokAt(3)->valueType());
11341+
ASSERT_EQUALS(f->tokAt(3)->scope(), f->tokAt(3)->valueType()->typeScope);
11342+
}
11343+
1132111344
void dumpFriend() {
1132211345
GET_SYMBOL_DB("class Foo {\n"
1132311346
" Foo();\n"

0 commit comments

Comments
 (0)