Skip to content

Commit 22f01f0

Browse files
IOBYTEdanmar
authored andcommitted
Fixed #9042 (Another using BOOL type breach) (cppcheck-opensource#1765)
1 parent 0f6a90c commit 22f01f0

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

lib/tokenize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,7 @@ bool Tokenizer::simplifyUsing()
18991899
}
19001900
if (tok == endOfTemplateDefinition) {
19011901
inTemplateDefinition = false;
1902+
endOfTemplateDefinition = nullptr;
19021903
continue;
19031904
}
19041905
}
@@ -2127,7 +2128,6 @@ bool Tokenizer::simplifyUsing()
21272128
str += " ;";
21282129
std::list<const Token *> callstack(1, usingStart);
21292130
mErrorLogger->reportErr(ErrorLogger::ErrorMessage(callstack, &list, Severity::debug, "debug",
2130-
21312131
"Failed to parse \'" + str + "\'. The checking continues anyway.", false));
21322132
}
21332133
}
@@ -2148,7 +2148,7 @@ bool Tokenizer::simplifyUsing()
21482148
if (usingEnd->next())
21492149
Token::eraseTokens(usingStart->previous(), usingEnd->next());
21502150
else {
2151-
Token::eraseTokens(usingStart, usingEnd);
2151+
Token::eraseTokens(usingStart->previous(), usingEnd);
21522152
usingEnd->deleteThis();
21532153
}
21542154
} else {

test/testpostfixoperator.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ class TestPostfixOperator : public TestFixture {
173173
"}");
174174
ASSERT_EQUALS("", errout.str());
175175

176+
// #9042
177+
check("template <class T>\n"
178+
"class c {\n"
179+
" int i = 0;\n"
180+
" c() { i--; }\n"
181+
"};\n"
182+
"template <class T>\n"
183+
"class s {};\n"
184+
"using BOOL = char;");
185+
ASSERT_EQUALS("", errout.str());
176186
}
177187

178188
void testfor() {

test/testsimplifyusing.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class TestSimplifyUsing : public TestFixture {
6363
TEST_CASE(simplifyUsing8971);
6464
TEST_CASE(simplifyUsing8976);
6565
TEST_CASE(simplifyUsing9040);
66+
TEST_CASE(simplifyUsing9042);
6667
}
6768

6869
std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) {
@@ -474,6 +475,27 @@ class TestSimplifyUsing : public TestFixture {
474475
ASSERT_EQUALS(exp, tok(code, true, Settings::Win64));
475476
}
476477

478+
void simplifyUsing9042() {
479+
const char code[] = "template <class T>\n"
480+
"class c {\n"
481+
" int i = 0;\n"
482+
" c() { i--; }\n"
483+
"};\n"
484+
"template <class T>\n"
485+
"class s {};\n"
486+
"using BOOL = char;";
487+
488+
const char exp[] = "template < class T > "
489+
"class c { "
490+
"int i ; i = 0 ; "
491+
"c ( ) { i -- ; } "
492+
"} ; "
493+
"template < class T > "
494+
"class s { } ;";
495+
496+
ASSERT_EQUALS(exp, tok(code, true, Settings::Win64));
497+
}
498+
477499
};
478500

479501
REGISTER_TEST(TestSimplifyUsing)

0 commit comments

Comments
 (0)