Skip to content

Commit f6527fc

Browse files
committed
fixed tests, unused templates are removed by default
1 parent 9947774 commit f6527fc

5 files changed

Lines changed: 10 additions & 34 deletions

File tree

lib/tokenize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4784,7 +4784,7 @@ void Tokenizer::simplifyHeaders()
47844784
// Maybe if --dump is used we want to have _everything_.
47854785

47864786
if (mSettings->checkHeaders && mSettings->checkUnusedTemplates)
4787-
// Default=full analysis. All information in the headers are kept.
4787+
// Full analysis. All information in the headers are kept.
47884788
return;
47894789

47904790
const bool checkHeaders = mSettings->checkHeaders;
@@ -4824,7 +4824,7 @@ void Tokenizer::simplifyHeaders()
48244824
const bool isIncluded = (tok->fileIndex() != 0);
48254825

48264826
// Remove executable code
4827-
if (isIncluded && mSettings->checkHeaders && tok->str() == "{") {
4827+
if (isIncluded && !mSettings->checkHeaders && tok->str() == "{") {
48284828
// TODO: We probably need to keep the executable code if this function is called from the source file.
48294829
const Token *prev = tok->previous();
48304830
while (prev && prev->isName())

test/testsimplifytemplate.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,7 @@ class TestSimplifyTemplate : public TestFixture {
386386

387387
// The expected result..
388388
const char expected[] = "class A<int> ; "
389-
"void f ( ) { A<int> a ; } "
390-
"template < typename T > class B { void g ( ) { A < T > b ; b = A < T > :: h ( ) ; } } ; "
389+
"void f ( ) { A<int> a ; } ; "
391390
"class A<int> { } ;";
392391

393392
ASSERT_EQUALS(expected, tok(code));
@@ -1386,7 +1385,6 @@ class TestSimplifyTemplate : public TestFixture {
13861385
"template <class T, unsigned S> C3<T, S>::C3(const C3<T, S> &v) { C1<T *> c1; }\n"
13871386
"C3<int,6> c3;";
13881387
const char exp[] = "struct C1<int*> ; "
1389-
"template < class T > void f ( ) { x = y ? ( C1 < int > :: allocate ( 1 ) ) : 0 ; } "
13901388
"class C3<int,6> ; "
13911389
"C3<int,6> c3 ; "
13921390
"class C3<int,6> { } ; "
@@ -2394,7 +2392,6 @@ class TestSimplifyTemplate : public TestFixture {
23942392
"template <typename T> class Fred {};\n"
23952393
"ObjectCache<Fred> _cache;";
23962394
const char exp[] = "class ObjectCache<Fred> ; "
2397-
"template < typename T > class Fred { } ; "
23982395
"ObjectCache<Fred> _cache ; "
23992396
"class ObjectCache<Fred> { } ;";
24002397
ASSERT_EQUALS(exp, tok(code));
@@ -2502,8 +2499,7 @@ class TestSimplifyTemplate : public TestFixture {
25022499
"template < class T > struct Unconst < const T & > { } ; "
25032500
"template < class T > struct Unconst < T * const > { } ; "
25042501
"template < class T1 , class T2 > struct type_equal { enum Anonymous0 { value = 0 } ; } ; "
2505-
"template < class T > struct type_equal < T , T > { enum Anonymous1 { value = 1 } ; } ; "
2506-
"template < class T > struct template_is_const { enum Anonymous2 { value = ! type_equal < T , Unconst < T > :: type > :: value } ; } ;";
2502+
"template < class T > struct type_equal < T , T > { enum Anonymous1 { value = 1 } ; } ;";
25072503
ASSERT_EQUALS(exp1, tok(code1));
25082504
}
25092505

@@ -2743,7 +2739,7 @@ class TestSimplifyTemplate : public TestFixture {
27432739
const char code[] = "class Fred {\n"
27442740
" template<class T> explicit Fred(T t) { }\n"
27452741
"}";
2746-
ASSERT_EQUALS("class Fred { template < class T > explicit Fred ( T t ) { } }", tok(code));
2742+
ASSERT_EQUALS("class Fred { }", tok(code));
27472743

27482744
// #3532
27492745
const char code2[] = "class Fred {\n"

test/testsimplifytypedef.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ class TestSimplifyTypedef : public TestFixture {
8080
TEST_CASE(simplifyTypedef36); // ticket #1434
8181
TEST_CASE(simplifyTypedef37); // ticket #1449
8282
TEST_CASE(simplifyTypedef38);
83-
TEST_CASE(simplifyTypedef39);
84-
TEST_CASE(simplifyTypedef40);
8583
TEST_CASE(simplifyTypedef43); // ticket #1588
8684
TEST_CASE(simplifyTypedef44);
8785
TEST_CASE(simplifyTypedef45); // ticket #1613
@@ -1190,23 +1188,6 @@ class TestSimplifyTypedef : public TestFixture {
11901188
ASSERT_EQUALS("", errout.str());
11911189
}
11921190

1193-
void simplifyTypedef39() {
1194-
const char code[] = "typedef int A;\n"
1195-
"template <const A, volatile A> struct S{};";
1196-
const char expected[] = "template < const int , volatile int > struct S { } ;";
1197-
ASSERT_EQUALS(expected, tok(code, false));
1198-
ASSERT_EQUALS("", errout.str());
1199-
}
1200-
1201-
void simplifyTypedef40() {
1202-
const char code[] = "typedef int A;\n"
1203-
"typedef int B;\n"
1204-
"template <class A, class B> class C { };";
1205-
const char expected[] = "template < class A , class B > class C { } ;";
1206-
ASSERT_EQUALS(expected, tok(code, false));
1207-
ASSERT_EQUALS("", errout.str());
1208-
}
1209-
12101191
void simplifyTypedef43() {
12111192
// ticket #1588
12121193
{
@@ -2546,8 +2527,7 @@ class TestSimplifyTypedef : public TestFixture {
25462527
"template <long, class> struct c; "
25472528
"template <int g> struct d { enum { e = c<g, b>::f }; };";
25482529
const char exp [] = "class a ; "
2549-
"template < long , class > struct c ; "
2550-
"template < int g > struct d { enum Anonymous0 { e = c < g , int ( a :: * ) > :: f } ; } ;";
2530+
"template < long , class > struct c ;";
25512531
ASSERT_EQUALS(exp, tok(code, false));
25522532
}
25532533

test/testsimplifyusing.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,7 @@ class TestSimplifyUsing : public TestFixture {
489489
"class c { "
490490
"int i ; i = 0 ; "
491491
"c ( ) { i -- ; } "
492-
"} ; "
493-
"template < class T > "
494-
"class s { } ;";
492+
"} ;";
495493

496494
ASSERT_EQUALS(exp, tok(code, true, Settings::Win64));
497495
}

test/testunusedfunctions.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ class TestUnusedFunctions : public TestFixture {
211211
"template<class T> void g()\n"
212212
"{\n"
213213
" f();\n"
214-
"}");
214+
"}\n"
215+
"\n"
216+
"void h() { g<int>(); h(); }");
215217
ASSERT_EQUALS("", errout.str());
216218
}
217219

0 commit comments

Comments
 (0)