@@ -311,6 +311,8 @@ class TestSimplifyTemplate : public TestFixture {
311
311
312
312
TEST_CASE (explicitBool1);
313
313
TEST_CASE (explicitBool2);
314
+
315
+ TEST_CASE (templateArgPreserveType); // #13882 - type of template argument
314
316
}
315
317
316
318
struct CheckOptions
@@ -677,7 +679,7 @@ class TestSimplifyTemplate : public TestFixture {
677
679
" vec<4> v ; "
678
680
" struct vec<4> { "
679
681
" vec<4> ( ) { } "
680
- " vec<4> ( const vec < 4 - 1 > & v ) { } "
682
+ " vec<4> ( const vec < ( int ) 4 - 1 > & v ) { } "
681
683
" } ;" ;
682
684
683
685
ASSERT_EQUALS (expected2, tok (code2));
@@ -1302,7 +1304,7 @@ class TestSimplifyTemplate : public TestFixture {
1302
1304
" int calculate_value<1,1> ( ) ; "
1303
1305
" int value ; value = calculate_value<1,1> ( ) ; "
1304
1306
" int calculate_value<1,1> ( ) { "
1305
- " if ( 1 != 1 ) { "
1307
+ " if ( ( int ) 1 != ( int ) 1 ) { "
1306
1308
" return sum<0> ( ) ; "
1307
1309
" } else { "
1308
1310
" return 0 ; "
@@ -1332,16 +1334,16 @@ class TestSimplifyTemplate : public TestFixture {
1332
1334
" } ; "
1333
1335
" const int x = Factorial<4> :: value ; "
1334
1336
" struct Factorial<4> { "
1335
- " enum Anonymous0 { value = 4 * Factorial<3> :: value } ; "
1337
+ " enum Anonymous0 { value = ( int ) 4 * Factorial<3> :: value } ; "
1336
1338
" } ; "
1337
1339
" struct Factorial<3> { "
1338
- " enum Anonymous0 { value = 3 * Factorial<2> :: value } ; "
1340
+ " enum Anonymous0 { value = ( int ) 3 * Factorial<2> :: value } ; "
1339
1341
" } ; "
1340
1342
" struct Factorial<2> { "
1341
- " enum Anonymous0 { value = 2 * Factorial<1> :: value } ; "
1343
+ " enum Anonymous0 { value = ( int ) 2 * Factorial<1> :: value } ; "
1342
1344
" } ; "
1343
1345
" struct Factorial<1> { "
1344
- " enum Anonymous0 { value = 1 * Factorial<0> :: value } ; "
1346
+ " enum Anonymous0 { value = ( int ) 1 * Factorial<0> :: value } ; "
1345
1347
" } ;" ;
1346
1348
ASSERT_EQUALS (expected, tok (code, dinit (CheckOptions, $.debugwarnings = true )));
1347
1349
ASSERT_EQUALS (" " , errout_str ());
@@ -1459,10 +1461,10 @@ class TestSimplifyTemplate : public TestFixture {
1459
1461
" int diagonalGroupTest<4> ( ) ; "
1460
1462
" int main ( ) { return diagonalGroupTest<4> ( ) ; } "
1461
1463
" int diagonalGroupTest<4> ( ) { return Factorial<4> :: value ; } "
1462
- " struct Factorial<4> { enum FacHelper { value = 4 * Factorial<3> :: value } ; } ; "
1463
- " struct Factorial<3> { enum FacHelper { value = 3 * Factorial<2> :: value } ; } ; "
1464
- " struct Factorial<2> { enum FacHelper { value = 2 * Factorial<1> :: value } ; } ; "
1465
- " struct Factorial<1> { enum FacHelper { value = 1 * Factorial<0> :: value } ; } ;" ;
1464
+ " struct Factorial<4> { enum FacHelper { value = ( int ) 4 * Factorial<3> :: value } ; } ; "
1465
+ " struct Factorial<3> { enum FacHelper { value = ( int ) 3 * Factorial<2> :: value } ; } ; "
1466
+ " struct Factorial<2> { enum FacHelper { value = ( int ) 2 * Factorial<1> :: value } ; } ; "
1467
+ " struct Factorial<1> { enum FacHelper { value = ( int ) 1 * Factorial<0> :: value } ; } ;" ;
1466
1468
ASSERT_EQUALS (exp, tok (code));
1467
1469
}
1468
1470
@@ -1558,11 +1560,11 @@ class TestSimplifyTemplate : public TestFixture {
1558
1560
" } ; "
1559
1561
" void A :: t_func<0> ( ) "
1560
1562
" { "
1561
- " if ( 0 != 0 || foo<int> ( ) ) { ; } "
1563
+ " if ( ( int ) 0 != 0 || foo<int> ( ) ) { ; } "
1562
1564
" } "
1563
1565
" void A :: t_func<1> ( ) "
1564
1566
" { "
1565
- " if ( 1 != 0 || foo<int> ( ) ) { ; } "
1567
+ " if ( ( int ) 1 != 0 || foo<int> ( ) ) { ; } "
1566
1568
" } "
1567
1569
" bool foo<int> ( ) { return true ; }" ;
1568
1570
ASSERT_EQUALS (exp, tok (code));
@@ -4765,15 +4767,15 @@ class TestSimplifyTemplate : public TestFixture {
4765
4767
" A<int,(int)2> a1;\n "
4766
4768
" A<int> a2;\n "
4767
4769
" }\n " ;
4768
- const char expected[] = " class A<int,(int) 2> ; "
4770
+ const char expected[] = " class A<int,2> ; "
4769
4771
" class A<int,3> ; "
4770
4772
" void f ( ) "
4771
4773
" { "
4772
- " A<int,(int) 2> a1 ; "
4774
+ " A<int,2> a1 ; "
4773
4775
" A<int,3> a2 ; "
4774
4776
" } "
4775
- " class A<int,(int) 2> "
4776
- " { int ar [ ( int ) 2 ] ; } ; "
4777
+ " class A<int,2> "
4778
+ " { int ar [ 2 ] ; } ; "
4777
4779
" class A<int,3> "
4778
4780
" { int ar [ 3 ] ; } ;" ;
4779
4781
ASSERT_EQUALS (expected, tok (code));
@@ -6311,7 +6313,7 @@ class TestSimplifyTemplate : public TestFixture {
6311
6313
" }" ;
6312
6314
const char expected[] = " struct A<0> ; "
6313
6315
" void bar ( ) { A<0> :: foo ( ) ; } "
6314
- " struct A<0> { static void foo ( ) { int i ; i = 0 ; } } ;" ;
6316
+ " struct A<0> { static void foo ( ) { int i ; i = ( int ) 0 ; } } ;" ;
6315
6317
ASSERT_EQUALS (expected, tok (code));
6316
6318
}
6317
6319
@@ -6586,6 +6588,17 @@ class TestSimplifyTemplate : public TestFixture {
6586
6588
const char code[] = " class Fred { explicit(false) Fred(int); };" ;
6587
6589
ASSERT_EQUALS (" class Fred { Fred ( int ) ; } ;" , tok (code));
6588
6590
}
6591
+
6592
+ void templateArgPreserveType () { // #13882 - type of template argument
6593
+ const char code[] = " template <uint32_t x> class Test {\n "
6594
+ " uint32_t i = x;\n "
6595
+ " };\n "
6596
+ " Test<64> test;\n " ;
6597
+ ASSERT_EQUALS (" class Test<64> ; "
6598
+ " Test<64> test ; "
6599
+ " class Test<64> { uint32_t i ; i = ( uint32_t ) 64 ; } ;" ,
6600
+ tok (code));
6601
+ }
6589
6602
};
6590
6603
6591
6604
REGISTER_TEST (TestSimplifyTemplate)
0 commit comments