diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index d84a70717..e33fdfc5f 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -743,6 +743,10 @@ void TemplateSimplifier::expandTemplate( } else if (tok3->str() == "}") { assert(brackets.empty() == false && brackets.top()->str() == "{"); Token::createMutualLinks(brackets.top(), tokenlist.back()); + if (tok3->strAt(1) == ";") { + const Token * tokSemicolon = tok3->next(); + tokenlist.addtoken(tokSemicolon, tokSemicolon->linenr(), tokSemicolon->fileIndex()); + } brackets.pop(); if (indentlevel <= 1 && brackets.empty()) { // there is a bug if indentlevel is 0 diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 210b272dc..c46e479c9 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -1674,7 +1674,7 @@ private: "Fred fred;"; const std::string expected("Fred fred ; " - "class Fred { int a ; }"); + "class Fred { int a ; } ;"); ASSERT_EQUALS(expected, tok(code)); } @@ -1684,7 +1684,7 @@ private: "Fred fred;"; const std::string expected("Fred fred ; " - "class Fred { float data [ 4 ] ; }"); + "class Fred { float data [ 4 ] ; } ;"); ASSERT_EQUALS(expected, tok(code)); } @@ -1694,7 +1694,7 @@ private: "Fred fred;"; const std::string expected("Fred fred ; " - "class Fred { Fred ( ) ; }"); + "class Fred { Fred ( ) ; } ;"); ASSERT_EQUALS(expected, tok(code)); } @@ -1706,7 +1706,7 @@ private: const std::string expected("template < classname T > Fred < T > :: Fred ( ) { } " // <- TODO: this should be removed "Fred fred ; " - "class Fred { } " + "class Fred { } ; " "Fred :: Fred ( ) { }"); ASSERT_EQUALS(expected, tok(code)); @@ -1719,7 +1719,7 @@ private: const std::string expected("Fred fred1 ; " "Fred fred2 ; " - "class Fred { }"); + "class Fred { } ;"); ASSERT_EQUALS(expected, tok(code)); } @@ -1833,7 +1833,7 @@ private: // The expected result.. std::string expected("void f ( ) { A a ; } " "template < typename T > class B { void g ( ) { A b ; b = A :: h ( ) ; } } ; " - "class A { } class A { }"); + "class A { } ; class A { } ;"); ASSERT_EQUALS(expected, tok(code)); } @@ -1890,7 +1890,7 @@ private: " A<12,12,11> a ; " "} " "class A<12,12,11> : public B < 12 , 12 , 0 > " - "{ }"); + "{ } ;"); ASSERT_EQUALS(expected, tok(code)); } @@ -2008,7 +2008,7 @@ private: "foo *f;"; const std::string expected("foo * f ; " - "class foo { int a ; }"); + "class foo { int a ; } ;"); ASSERT_EQUALS(expected, tok(code)); } @@ -2048,7 +2048,7 @@ private: // The expected result.. const std::string expected("template < class T > A < T > :: ~ A ( ) { } " // <- TODO: this should be removed "A a ; " - "class A { public: ~ A ( ) ; } " + "class A { public: ~ A ( ) ; } ; " "A :: ~ A ( ) { }"); ASSERT_EQUALS(expected, tok(code)); } @@ -2059,7 +2059,7 @@ private: "Fred fred;"; const std::string expected("Fred fred ; " - "struct Fred { int a ; }"); + "struct Fred { int a ; } ;"); ASSERT_EQUALS(expected, tok(code)); } @@ -2069,7 +2069,7 @@ private: "Fred fred;"; const std::string expected("Fred fred ; " - "struct Fred { float data [ 4 ] ; }"); + "struct Fred { float data [ 4 ] ; } ;"); ASSERT_EQUALS(expected, tok(code)); } @@ -2079,7 +2079,7 @@ private: "Fred fred;"; const std::string expected("Fred fred ; " - "struct Fred { Fred ( ) ; }"); + "struct Fred { Fred ( ) ; } ;"); ASSERT_EQUALS(expected, tok(code)); } @@ -2091,7 +2091,7 @@ private: const std::string expected("Fred fred1 ; " "Fred fred2 ; " - "struct Fred { }"); + "struct Fred { } ;"); ASSERT_EQUALS(expected, tok(code)); } @@ -2102,7 +2102,7 @@ private: "Fred fred;"; const std::string expected("Fred fred ; " - "struct Fred { std :: string a ; }"); + "struct Fred { std :: string a ; } ;"); ASSERT_EQUALS(expected, tok(code)); } @@ -2133,8 +2133,8 @@ private: "\n" "bitset<1> z;"; const char expected[] = "bitset<1> z ; " - "class bitset<1> : B<4> { } " - "struct B<4> { int a [ 4 ] ; }"; + "class bitset<1> : B<4> { } ; " + "struct B<4> { int a [ 4 ] ; } ;"; ASSERT_EQUALS(expected, tok(code)); } @@ -2151,11 +2151,11 @@ private: const char actual[] = "template < int n > struct B { int a [ n ] ; } ; " "bitset<1> z ; " - "class bitset<1> : B < 4 > { }"; + "class bitset<1> : B < 4 > { } ;"; const char expected[] = "bitset<1> z ; " - "class bitset<1> : B<4> { } " - "struct B<4> { int a [ 4 ] ; }"; + "class bitset<1> : B<4> { } ; " + "struct B<4> { int a [ 4 ] ; } ;"; TODO_ASSERT_EQUALS(expected, actual, tok(code)); @@ -2171,7 +2171,7 @@ private: "\n" "C<2> a;\n"; // TODO: expand A also - ASSERT_EQUALS("template < class T > class A { public: T x ; } ; C<2> a ; class C<2> : public A < char [ 2 ] > { }", tok(code)); + ASSERT_EQUALS("template < class T > class A { public: T x ; } ; C<2> a ; class C<2> : public A < char [ 2 ] > { } ;", tok(code)); } void template27() { @@ -2184,7 +2184,7 @@ private: // #3226 - inner template const char code[] = "template class Fred {};\n" "Fred > x;\n"; - ASSERT_EQUALS("Fred> x ; class Fred { } class Fred> { }", tok(code)); + ASSERT_EQUALS("Fred> x ; class Fred { } ; class Fred> { } ;", tok(code)); } void template29() { @@ -2204,7 +2204,7 @@ private: void template31() { // #4010 - template reference type const char code[] = "template struct A{}; A a;"; - ASSERT_EQUALS("A a ; struct A { }", tok(code)); + ASSERT_EQUALS("A a ; struct A { } ;", tok(code)); } void template32() { @@ -2221,7 +2221,7 @@ private: "B b;\n"; ASSERT_EQUALS("template < class T1 , class T2 , class T3 , class T4 > struct A { } ; " "B b ; " - "struct B { public: A < int , Pair < int , int > , int > a ; }", tok(code)); + "struct B { public: A < int , Pair < int , int > , int > a ; } ;", tok(code)); } void template33() { @@ -2232,10 +2232,10 @@ private: "template struct C { A > > ab; };\n" "C c;"; ASSERT_EQUALS("C c ; " - "struct C { A>> ab ; } " - "struct B> { } " // <- redundant.. but nevermind - "struct A>> { } " // <- redundant.. but nevermind - "struct A>> { }", tok(code)); + "struct C { A>> ab ; } ; " + "struct B> { } ; " // <- redundant.. but nevermind + "struct A>> { } ; " // <- redundant.. but nevermind + "struct A>> { } ;", tok(code)); } { @@ -2246,7 +2246,7 @@ private: "C< B > c;"; ASSERT_EQUALS("struct A { } ; " "template < class T > struct B { } ; " // <- redundant.. but nevermind - "C> c ; struct C> { }", + "C> c ; struct C> { } ;", tok(code)); } } @@ -2266,7 +2266,7 @@ private: void template35() { // #4074 - "A<'x'> a;" is not recognized as template instantiation const char code[] = "template class A {};\n" "A<'x'> a;"; - ASSERT_EQUALS("A<'x'> a ; class A<'x'> { }", tok(code)); + ASSERT_EQUALS("A<'x'> a ; class A<'x'> { } ;", tok(code)); } void template36() { // #4310 - Passing unknown template instantiation as template argument @@ -2274,8 +2274,8 @@ private: "template struct Y { Foo < X< Bar > > _foo; };\n" // <- Bar is unknown "Y bar;"; ASSERT_EQUALS("Y bar ; " - "struct Y { Foo < X> > _foo ; } " - "struct X> { Bar < int > t ; }", + "struct Y { Foo < X> > _foo ; } ; " + "struct X> { Bar < int > t ; } ;", tok(code)); } @@ -2284,7 +2284,7 @@ private: "template class B {};\n" "B b1;\n" "B b2;"; - ASSERT_EQUALS("class A { } ; B b1 ; B b2 ; class B { }", + ASSERT_EQUALS("class A { } ; B b1 ; B b2 ; class B { } ;", tok(code)); } @@ -2329,7 +2329,7 @@ private: void template41() { // #4710 - const in template instantiation not handled perfectly const char code1[] = "template struct X { };\n" "void f(const X x) { }"; - ASSERT_EQUALS("void f ( const X x ) { } struct X { }", tok(code1)); + ASSERT_EQUALS("void f ( const X x ) { } struct X { } ;", tok(code1)); const char code2[] = "template T f(T t) { return t; }\n" "int x() { return f(123); }"; @@ -2381,9 +2381,9 @@ private: " A a2 ; " "} " "class A " - "{ int ar [ 2 ] ; } " + "{ int ar [ 2 ] ; } ; " "class A " - "{ int ar [ 3 ] ; }"); + "{ int ar [ 3 ] ; } ;"); ASSERT_EQUALS(expected, tok(code)); } { @@ -2404,7 +2404,7 @@ private: " A a2 ; " "} " "class A " - "{ int ar [ 5 ] ; }"); + "{ int ar [ 5 ] ; } ;"); ASSERT_EQUALS(expected, tok(code)); } { @@ -2437,7 +2437,7 @@ private: "A a2 ; " "} " "class A " - "{ int ar [ 3 ] ; }" + "{ int ar [ 3 ] ; } ;" ); TODO_ASSERT_EQUALS(wanted, current, tok(code)); }