From 1e57f54917d6f990ba12279c66d021ce131760c3 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sun, 16 Mar 2014 19:55:32 +0100 Subject: [PATCH] Fixed #5481: std::array is POD, so using memcpy (etc.) is allowed on it. --- lib/checkclass.cpp | 2 +- test/testclass.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index f88a4236c..eb617f243 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1054,7 +1054,7 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco const Scope *typeScope = var->typeScope(); // check for std:: type - if (var->isStlType()) + if (var->isStlType() && tok1->strAt(2) != "array") if (allocation) mallocOnClassError(tok, tok->str(), type->classDef, "'std::" + tok1->strAt(2) + "'"); else diff --git a/test/testclass.cpp b/test/testclass.cpp index ab79b3c87..41d4d0757 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -2507,6 +2507,15 @@ private: "[test.cpp:11]: (error) Using 'memset' on struct that contains a 'std::string'.\n" "[test.cpp:12]: (error) Using 'memset' on struct that contains a 'std::string'.\n" "[test.cpp:13]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout.str()); + + checkNoMemset("class A {\n" + " std::array ints;\n" + "};\n" + "void f() {\n" + " A a;\n" + " memset(&a, 0, sizeof(A));\n" + "}"); + ASSERT_EQUALS("", errout.str()); // std::array is POD (#5481) } void mallocOnClass() {