parent
df860a937d
commit
789c032e42
|
@ -1200,16 +1200,22 @@ static int estimateSize(const Type* type, const Settings* settings, const Symbol
|
|||
else
|
||||
cumulatedSize += size;
|
||||
};
|
||||
for (const Variable&var : type->classScope->varlist) {
|
||||
std::set<const Scope*> anonScopes;
|
||||
for (const Variable& var : type->classScope->varlist) {
|
||||
int size = 0;
|
||||
if (var.isStatic())
|
||||
continue;
|
||||
if (var.isPointer() || var.isReference())
|
||||
size = settings->platform.sizeof_pointer;
|
||||
else if (var.type() && var.type()->classScope)
|
||||
size = estimateSize(var.type(), settings, symbolDatabase, recursionDepth+1);
|
||||
size = estimateSize(var.type(), settings, symbolDatabase, recursionDepth + 1);
|
||||
else if (var.valueType() && var.valueType()->type == ValueType::Type::CONTAINER)
|
||||
size = 3 * settings->platform.sizeof_pointer; // Just guess
|
||||
else if (var.nameToken()->scope() != type->classScope && var.nameToken()->scope()->definedType) { // anonymous union
|
||||
const auto ret = anonScopes.insert(var.nameToken()->scope());
|
||||
if (ret.second)
|
||||
size = estimateSize(var.nameToken()->scope()->definedType, settings, symbolDatabase, recursionDepth + 1);
|
||||
}
|
||||
else
|
||||
size = symbolDatabase->sizeOfType(var.typeStartToken());
|
||||
|
||||
|
|
|
@ -2172,6 +2172,25 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 't' should be passed by const reference.\n", errout.str());
|
||||
|
||||
check("struct S {\n" // #12138
|
||||
" union {\n"
|
||||
" int a = 0;\n"
|
||||
" int x;\n"
|
||||
" };\n"
|
||||
" union {\n"
|
||||
" int b = 0;\n"
|
||||
" int y;\n"
|
||||
" };\n"
|
||||
" union {\n"
|
||||
" int c = 0;\n"
|
||||
" int z;\n"
|
||||
" };\n"
|
||||
"};\n"
|
||||
"void f(S s) {\n"
|
||||
" if (s.x > s.y) {}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build();
|
||||
check("using ui64 = unsigned __int64;\n"
|
||||
"ui64 Test(ui64 one, ui64 two) { return one + two; }\n",
|
||||
|
|
Loading…
Reference in New Issue