Skip to content

Commit 37c4492

Browse files
committed
Treat an array of std::array parameter as decayed in isDecayedArrayArgument
1 parent 935cae0 commit 37c4492

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎lib/symboldatabase.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2720,7 +2720,9 @@ bool Variable::isStlStringViewType() const
27202720

27212721
bool Variable::isDecayedArrayArgument() const
27222722
{
2723-
return isArray() && isArgument() && !isReference() && !(isStlType() && getTypeName() == "std::array");
2723+
if (!isArray() || !isArgument() || isReference())
2724+
return false;
2725+
return !(isStlType() && getTypeName() == "std::array") || Token::simpleMatch(nameToken()->next(), "[");
27242726
}
27252727

27262728
std::string Variable::getTypeName() const

‎test/testsizeof.cpp‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,12 @@ class TestSizeof : public TestFixture {
339339
"}\n"
340340
"int g(std::string a[2]) {\n"
341341
" return sizeof(a);\n"
342+
"}\n"
343+
"int h(std::array<int, 2> a[2]) {\n"
344+
" return sizeof(a);\n"
342345
"}\n");
343-
ASSERT_EQUALS("[test.cpp:5:12]: (warning) Using 'sizeof' on array given as function argument returns size of a pointer. [sizeofwithsilentarraypointer]\n",
346+
ASSERT_EQUALS("[test.cpp:5:12]: (warning) Using 'sizeof' on array given as function argument returns size of a pointer. [sizeofwithsilentarraypointer]\n"
347+
"[test.cpp:8:12]: (warning) Using 'sizeof' on array given as function argument returns size of a pointer. [sizeofwithsilentarraypointer]\n",
344348
errout_str());
345349
}
346350

‎test/testvalueflow.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,13 @@ class TestValueFlow : public TestFixture {
16321632
ASSERT_EQUALS(1U, values.size());
16331633
ASSERT_EQUALS(10, values.back().intvalue);
16341634

1635+
code = "void f(std::array<int, 4> a[2]) {\n" // array of std::array parameter is a pointer
1636+
" x = sizeof(a);\n"
1637+
"}\n";
1638+
values = tokenValues(code, "( a )");
1639+
ASSERT_EQUALS(1U, values.size());
1640+
ASSERT_EQUALS(settings.platform.sizeof_pointer, values.back().intvalue);
1641+
16351642
#define CHECK(A, B, C, D) \
16361643
do { \
16371644
code = "enum " A " E " B " { E0, E1 };\n" \

0 commit comments

Comments
 (0)