Skip to content

Commit a709c86

Browse files
Fix #14860 FP sizeofwithsilentarraypointer with std::array (#8661)
1 parent ed596da commit a709c86

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/checksizeof.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void CheckSizeofImpl::checkSizeofForArrayParameter()
8787
}
8888

8989
const Variable *var = varTok->variable();
90-
if (var && var->isArray() && var->isArgument() && !var->isReference())
90+
if (var && var->isArray() && var->isArgument() && !var->isReference() && !(var->isStlType() && var->getTypeName() == "std::array"))
9191
sizeofForArrayParameterError(tok);
9292
}
9393
}

test/testsizeof.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,14 @@ class TestSizeof : public TestFixture {
334334
"}");
335335
ASSERT_EQUALS("", errout_str());
336336

337+
check("int f(std::array<int, 2> a) {\n" // #14860
338+
" return sizeof(a);\n"
339+
"}\n"
340+
"int g(std::string a[2]) {\n"
341+
" return sizeof(a);\n"
342+
"}\n");
343+
ASSERT_EQUALS("[test.cpp:5:12]: (warning) Using 'sizeof' on array given as function argument returns size of a pointer. [sizeofwithsilentarraypointer]\n",
344+
errout_str());
337345
}
338346

339347
void sizeofForNumericParameter() {

0 commit comments

Comments
 (0)