Don't suggestInitializationList for arrays used as initializer (#5640)

This commit is contained in:
PKEuS 2014-04-10 22:28:02 +02:00
parent 2aaae741dd
commit b10fce304e
2 changed files with 14 additions and 0 deletions

View File

@ -792,6 +792,9 @@ void CheckClass::initializationListUsage()
tok2->strAt(-1)!=".") { // Is there a dependency between two member variables? tok2->strAt(-1)!=".") { // Is there a dependency between two member variables?
allowed = false; allowed = false;
break; 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 } else if (tok2->str() == "this") { // 'this' instance is not completely constructed in initialization list
allowed = false; allowed = false;

View File

@ -5733,6 +5733,17 @@ private:
" Fred() { s = \"foo\"; }\n" " Fred() { s = \"foo\"; }\n"
"};"); "};");
ASSERT_EQUALS("", errout.str()); 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." // ticket #4290 "False Positive: style (noConstructor): The class 'foo' does not have a constructor."