@@ -311,6 +311,8 @@ class TestSimplifyTemplate : public TestFixture {
311311
312312 TEST_CASE (explicitBool1);
313313 TEST_CASE (explicitBool2);
314+
315+ TEST_CASE (templateArgPreserveType); // #13882 - type of template argument
314316 }
315317
316318 struct CheckOptions
@@ -677,7 +679,7 @@ class TestSimplifyTemplate : public TestFixture {
677679 " vec<4> v ; "
678680 " struct vec<4> { "
679681 " vec<4> ( ) { } "
680- " vec<4> ( const vec < 4 - 1 > & v ) { } "
682+ " vec<4> ( const vec < ( int ) 4 - 1 > & v ) { } "
681683 " } ;" ;
682684
683685 ASSERT_EQUALS (expected2, tok (code2));
@@ -1302,7 +1304,7 @@ class TestSimplifyTemplate : public TestFixture {
13021304 " int calculate_value<1,1> ( ) ; "
13031305 " int value ; value = calculate_value<1,1> ( ) ; "
13041306 " int calculate_value<1,1> ( ) { "
1305- " if ( 1 != 1 ) { "
1307+ " if ( ( int ) 1 != ( int ) 1 ) { "
13061308 " return sum<0> ( ) ; "
13071309 " } else { "
13081310 " return 0 ; "
@@ -1332,16 +1334,16 @@ class TestSimplifyTemplate : public TestFixture {
13321334 " } ; "
13331335 " const int x = Factorial<4> :: value ; "
13341336 " struct Factorial<4> { "
1335- " enum Anonymous0 { value = 4 * Factorial<3> :: value } ; "
1337+ " enum Anonymous0 { value = ( int ) 4 * Factorial<3> :: value } ; "
13361338 " } ; "
13371339 " struct Factorial<3> { "
1338- " enum Anonymous0 { value = 3 * Factorial<2> :: value } ; "
1340+ " enum Anonymous0 { value = ( int ) 3 * Factorial<2> :: value } ; "
13391341 " } ; "
13401342 " struct Factorial<2> { "
1341- " enum Anonymous0 { value = 2 * Factorial<1> :: value } ; "
1343+ " enum Anonymous0 { value = ( int ) 2 * Factorial<1> :: value } ; "
13421344 " } ; "
13431345 " struct Factorial<1> { "
1344- " enum Anonymous0 { value = 1 * Factorial<0> :: value } ; "
1346+ " enum Anonymous0 { value = ( int ) 1 * Factorial<0> :: value } ; "
13451347 " } ;" ;
13461348 ASSERT_EQUALS (expected, tok (code, dinit (CheckOptions, $.debugwarnings = true )));
13471349 ASSERT_EQUALS (" " , errout_str ());
@@ -1459,10 +1461,10 @@ class TestSimplifyTemplate : public TestFixture {
14591461 " int diagonalGroupTest<4> ( ) ; "
14601462 " int main ( ) { return diagonalGroupTest<4> ( ) ; } "
14611463 " 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 } ; } ;" ;
14661468 ASSERT_EQUALS (exp, tok (code));
14671469 }
14681470
@@ -1558,11 +1560,11 @@ class TestSimplifyTemplate : public TestFixture {
15581560 " } ; "
15591561 " void A :: t_func<0> ( ) "
15601562 " { "
1561- " if ( 0 != 0 || foo<int> ( ) ) { ; } "
1563+ " if ( ( int ) 0 != 0 || foo<int> ( ) ) { ; } "
15621564 " } "
15631565 " void A :: t_func<1> ( ) "
15641566 " { "
1565- " if ( 1 != 0 || foo<int> ( ) ) { ; } "
1567+ " if ( ( int ) 1 != 0 || foo<int> ( ) ) { ; } "
15661568 " } "
15671569 " bool foo<int> ( ) { return true ; }" ;
15681570 ASSERT_EQUALS (exp, tok (code));
@@ -4765,15 +4767,15 @@ class TestSimplifyTemplate : public TestFixture {
47654767 " A<int,(int)2> a1;\n "
47664768 " A<int> a2;\n "
47674769 " }\n " ;
4768- const char expected[] = " class A<int,(int) 2> ; "
4770+ const char expected[] = " class A<int,2> ; "
47694771 " class A<int,3> ; "
47704772 " void f ( ) "
47714773 " { "
4772- " A<int,(int) 2> a1 ; "
4774+ " A<int,2> a1 ; "
47734775 " A<int,3> a2 ; "
47744776 " } "
4775- " class A<int,(int) 2> "
4776- " { int ar [ ( int ) 2 ] ; } ; "
4777+ " class A<int,2> "
4778+ " { int ar [ 2 ] ; } ; "
47774779 " class A<int,3> "
47784780 " { int ar [ 3 ] ; } ;" ;
47794781 ASSERT_EQUALS (expected, tok (code));
@@ -6311,7 +6313,7 @@ class TestSimplifyTemplate : public TestFixture {
63116313 " }" ;
63126314 const char expected[] = " struct A<0> ; "
63136315 " 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 ; } } ;" ;
63156317 ASSERT_EQUALS (expected, tok (code));
63166318 }
63176319
@@ -6586,6 +6588,17 @@ class TestSimplifyTemplate : public TestFixture {
65866588 const char code[] = " class Fred { explicit(false) Fred(int); };" ;
65876589 ASSERT_EQUALS (" class Fred { Fred ( int ) ; } ;" , tok (code));
65886590 }
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+ }
65896602};
65906603
65916604REGISTER_TEST (TestSimplifyTemplate)
0 commit comments