Skip to content

Commit b39afb2

Browse files
committed
Revert "Fixed cppcheck-opensource#4419 (False positive: Class does not have a constructor)"
This reverts commit 9a79961. There is a segmentation fault when checking lib/preprocessor.cpp
1 parent 9a79961 commit b39afb2

4 files changed

Lines changed: 5 additions & 35 deletions

File tree

‎lib/checkclass.cpp‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,6 @@ void CheckClass::initializeVarList(const Function &func, std::list<std::string>
367367
if (level == 0 && Token::Match(ftok, "%var% (")) {
368368
if (ftok->strAt(2) != ")")
369369
initVar(ftok->str(), scope, usage);
370-
} else if (level == 0 && Token::Match(ftok, "%var% {")) {
371-
initVar(ftok->str(), scope, usage);
372-
ftok = ftok->linkAt(1);
373370
} else if (level != 0 && Token::Match(ftok, "%var% =")) // assignment in the initializer: var(value = x)
374371
assignVar(ftok->str(), scope, usage);
375372

‎lib/symboldatabase.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
916916
tok->strAt(-1) == "::" || tok->strAt(-1) == "~" || // or a scope qualifier in front of tok
917917
outerScope->isClassOrStruct()) && // or a ctor/dtor
918918
(Token::Match(tok->next()->link(), ") const| ;|{|=") ||
919-
Token::Match(tok->next()->link(), ") : ::| %var% (|::|<|{"))) {
919+
Token::Match(tok->next()->link(), ") : ::| %var% (|::"))) {
920920
*funcStart = tok;
921921
*argStart = tok->next();
922922
return true;
@@ -1251,8 +1251,8 @@ void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok)
12511251
Scope *new_scope = &scopeList.back();
12521252

12531253
// skip to start of function
1254-
while (tok1 && ((tok1->str() != "{") || (tok1->previous() && tok1->previous()->isName() && tok1->strAt(-1) != "const"))) {
1255-
if (tok1->str() == "(" || tok1->str() == "{")
1254+
while (tok1 && tok1->str() != "{") {
1255+
if (tok1->str() == "(")
12561256
tok1 = tok1->link();
12571257
tok1 = tok1->next();
12581258
}

‎test/testclass.cpp‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class TestClass : public TestFixture {
5353
TEST_CASE(noConstructor6); // ticket #4386
5454
TEST_CASE(noConstructor7); // ticket #4391
5555
TEST_CASE(noConstructor8); // ticket #4404
56-
TEST_CASE(noConstructor9); // ticket #4419
5756

5857
TEST_CASE(operatorEq1);
5958
TEST_CASE(operatorEq2);
@@ -1914,17 +1913,6 @@ class TestClass : public TestFixture {
19141913
ASSERT_EQUALS("", errout.str());
19151914
}
19161915

1917-
void noConstructor9() {
1918-
// ticket #4419
1919-
checkNoConstructor("class CGreeting : public CGreetingBase<char> {\n"
1920-
"public:\n"
1921-
" CGreeting() : CGreetingBase<char>(), MessageSet(false) {}\n"
1922-
"private:\n"
1923-
" bool MessageSet;\n"
1924-
"};\n");
1925-
ASSERT_EQUALS("", errout.str());
1926-
}
1927-
19281916
void checkNoMemset(const char code[]) {
19291917
// Clear the error log
19301918
errout.str("");

‎test/testconstructors.cpp‎

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ class TestConstructors : public TestFixture {
124124
TEST_CASE(uninitVarArray8);
125125
TEST_CASE(uninitVarArray2D);
126126
TEST_CASE(uninitVarArray3D);
127-
TEST_CASE(uninitVarCpp11Init1);
128-
TEST_CASE(uninitVarCpp11Init2);
127+
TEST_CASE(uninitVarCpp11Init);
129128
TEST_CASE(uninitVarStruct1); // ticket #2172
130129
TEST_CASE(uninitVarStruct2); // ticket #838
131130
TEST_CASE(uninitVarUnion1); // ticket #3196
@@ -1815,7 +1814,7 @@ class TestConstructors : public TestFixture {
18151814
ASSERT_EQUALS("", errout.str());
18161815
}
18171816

1818-
void uninitVarCpp11Init1() {
1817+
void uninitVarCpp11Init() {
18191818
check("class Foo {\n"
18201819
" std::vector<std::string> bar;\n"
18211820
"public:\n"
@@ -1826,20 +1825,6 @@ class TestConstructors : public TestFixture {
18261825
ASSERT_EQUALS("", errout.str());
18271826
}
18281827

1829-
void uninitVarCpp11Init2() {
1830-
check("class Fred {\n"
1831-
" struct Foo {\n"
1832-
" int a;\n"
1833-
" bool b;\n"
1834-
" };\n"
1835-
" Foo f;\n"
1836-
" float g;\n"
1837-
"public:\n"
1838-
" Fred() : f{0, true} { }\n"
1839-
"};");
1840-
ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'Fred::g' is not initialized in the constructor.\n", errout.str());
1841-
}
1842-
18431828
void uninitVarStruct1() { // ticket #2172
18441829
check("class A\n"
18451830
"{\n"

0 commit comments

Comments
 (0)