From b10fce304e9a9b15061550b9bd13bc3242eb5882 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 10 Apr 2014 22:28:02 +0200 Subject: [PATCH] Don't suggestInitializationList for arrays used as initializer (#5640) --- lib/checkclass.cpp | 3 +++ test/testclass.cpp | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index f172a9d3d..4f1e07474 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -792,6 +792,9 @@ void CheckClass::initializationListUsage() tok2->strAt(-1)!=".") { // Is there a dependency between two member variables? allowed = false; break; + } else if (var2 && (var2->isArray() && var2->isLocal())) { // Can't initialize an array + allowed = false; + break; } } else if (tok2->str() == "this") { // 'this' instance is not completely constructed in initialization list allowed = false; diff --git a/test/testclass.cpp b/test/testclass.cpp index b356f9b4d..5a04fb17e 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -5733,6 +5733,17 @@ private: " Fred() { s = \"foo\"; }\n" "};"); ASSERT_EQUALS("", errout.str()); + + checkInitializationListUsage("class Fred {\n" // #5640 + " std::string s;\n" + " Fred() {\n" + " char str[2];\n" + " str[0] = c;\n" + " str[1] = 0;\n" + " s = str;\n" + " }\n" + "};"); + ASSERT_EQUALS("", errout.str()); } // ticket #4290 "False Positive: style (noConstructor): The class 'foo' does not have a constructor."