Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6528,7 +6528,7 @@ static void valueFlowContainerSize(const TokenList& tokenlist,
const Dimension& dim = var->dimensions().front();
if (dim.known) {
size = dim.num;
} else if (dim.tok && dim.tok->hasKnownIntValue()) {
} else if (dim.tok && dim.tok->hasKnownIntValue() && dim.tok->strAt(1) == ">") {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are only two containers with <size templateParameter= in our library, std::array and std::bitset. The size parameter comes last for both of them.

size = dim.tok->values().front().intvalue;
}
}
Expand Down
6 changes: 6 additions & 0 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7158,6 +7158,12 @@ class TestValueFlow : public TestFixture {
" return v[2];\n"
"}";
ASSERT(isKnownContainerSizeValue(tokenValues(code, "v ["), 3).empty());

code = "auto f() {\n" // #13654
" std::array<uint8_t, 6 * sizeof(uint16_t)> a{};\n"
" return a[0];\n"
"}";
ASSERT(!isKnownContainerSizeValue(tokenValues(code, "a ["), 6).empty());
}

void valueFlowContainerElement()
Expand Down
Loading