Skip to content

Commit

Permalink
Fix #11893 FP constStatement unused variable (danmar#5567)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Oct 19, 2023
1 parent e1a120e commit 7c3ae68
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/templatesimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2246,13 +2246,13 @@ void TemplateSimplifier::expandTemplate(
assert(brackets.empty() == false);
assert(brackets.top()->str() == "{");
Token::createMutualLinks(brackets.top(), mTokenList.back());
if (tok3->strAt(1) == ";") {
const Token * tokSemicolon = tok3->next();
mTokenList.addtoken(tokSemicolon, tokSemicolon->linenr(), tokSemicolon->column(), tokSemicolon->fileIndex());
}
brackets.pop();
if (brackets.empty() && !Token::Match(tok3, "} >|,|{")) {
inTemplateDefinition = false;
if (isClass && tok3->strAt(1) == ";") {
const Token* tokSemicolon = tok3->next();
mTokenList.addtoken(tokSemicolon, tokSemicolon->linenr(), tokSemicolon->column(), tokSemicolon->fileIndex());
}
break;
}
} else if (tok3->str() == ")") {
Expand Down
31 changes: 30 additions & 1 deletion test/testsimplifytemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class TestSimplifyTemplate : public TestFixture {
TEST_CASE(template175); // #10908
TEST_CASE(template176); // #11146
TEST_CASE(template177);
TEST_CASE(template178);
TEST_CASE(template_specialization_1); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
TEST_CASE(template_specialization_2); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template)
Expand Down Expand Up @@ -4518,6 +4519,34 @@ class TestSimplifyTemplate : public TestFixture {
ASSERT_EQUALS(exp, tok(code));
}

void template178() {
const char code[] = "template<typename T>\n" // #11893
"void g() {\n"
" for (T i = 0; i < T{ 3 }; ++i) {}\n"
"}\n"
"void f() {\n"
" g<int>();\n"
"}";
const char exp[] = "void g<int> ( ) ; void f ( ) { g<int> ( ) ; } void g<int> ( ) { for ( int i = 0 ; i < int { 3 } ; ++ i ) { } }";
ASSERT_EQUALS(exp, tok(code));

const char code2[] = "template<typename T>\n"
"struct S {\n"
" T c;\n"
" template<typename U>\n"
" void g() {\n"
" for (U i = 0; i < U{ 3 }; ++i) {}\n"
" }\n"
"};\n"
"void f() {\n"
" S<char> s{};\n"
" s.g<int>();\n"
"}";
const char exp2[] = "struct S<char> ; void f ( ) { S<char> s { } ; s . g<int> ( ) ; } struct S<char> { char c ; void g<int> ( ) ; } ; "
"void S<char> :: g<int> ( ) { for ( int i = 0 ; i < int { 3 } ; ++ i ) { } }";
ASSERT_EQUALS(exp2, tok(code2));
}

void template_specialization_1() { // #7868 - template specialization template <typename T> struct S<C<T>> {..};
const char code[] = "template <typename T> struct C {};\n"
"template <typename T> struct S {a};\n"
Expand Down Expand Up @@ -5229,7 +5258,7 @@ class TestSimplifyTemplate : public TestFixture {
void template_array_type() {
ASSERT_EQUALS("void foo<int[]> ( int [ ] x ) ; "
"void bar ( ) { int [ 3 ] y ; foo<int[]> ( y ) ; } "
"void foo<int[]> ( int [ ] x ) { } ;",
"void foo<int[]> ( int [ ] x ) { }",
tok("template <class T> void foo(T x) {};\n"
"void bar() {\n"
" int[3] y;\n"
Expand Down

0 comments on commit 7c3ae68

Please sign in to comment.