@@ -2296,10 +2296,10 @@ class TestSimplifyTemplate : public TestFixture {
22962296 " long f1 = fib<1>;\n "
22972297 " long f2 = fib<2>;\n "
22982298 " long f3 = fib<3>;" ;
2299- const char exp[] = " const long fib<2> = fib<1> + fib<0> ; "
2300- " const long fib<3> = fib<2> + fib<1> ; "
2301- " const long fib<0> = 0 ; "
2302- " const long fib<1> = 1 ; "
2299+ const char exp[] = " constexpr long fib<2> = fib<1> + fib<0> ; "
2300+ " constexpr long fib<3> = fib<2> + fib<1> ; "
2301+ " constexpr long fib<0> = 0 ; "
2302+ " constexpr long fib<1> = 1 ; "
23032303 " long f0 ; f0 = fib<0> ; "
23042304 " long f1 ; f1 = fib<1> ; "
23052305 " long f2 ; f2 = fib<2> ; "
@@ -2314,12 +2314,12 @@ class TestSimplifyTemplate : public TestFixture {
23142314 " template<>\n "
23152315 " constexpr long fib<1> = 1;\n "
23162316 " long f5 = fib<5>;\n " ;
2317- const char exp[] = " const long fib<5> = fib<4> + fib<3> ; "
2318- " const long fib<4> = fib<3> + fib<2> ; "
2319- " const long fib<3> = fib<2> + fib<1> ; "
2320- " const long fib<2> = fib<1> + fib<0> ; "
2321- " const long fib<0> = 0 ; "
2322- " const long fib<1> = 1 ; "
2317+ const char exp[] = " constexpr long fib<5> = fib<4> + fib<3> ; "
2318+ " constexpr long fib<4> = fib<3> + fib<2> ; "
2319+ " constexpr long fib<3> = fib<2> + fib<1> ; "
2320+ " constexpr long fib<2> = fib<1> + fib<0> ; "
2321+ " constexpr long fib<0> = 0 ; "
2322+ " constexpr long fib<1> = 1 ; "
23232323 " long f5 ; f5 = fib<5> ;" ;
23242324 ASSERT_EQUALS (exp, tok (code));
23252325 }
@@ -2933,8 +2933,8 @@ class TestSimplifyTemplate : public TestFixture {
29332933 " constexpr auto funcBraced = [](auto x){ return T{x};};\n "
29342934 " double f(int x) { return func<double>(x); }\n "
29352935 " double fBraced(int x) { return funcBraced<int>(x); }" ;
2936- const char exp[] = " const auto func<double> = [ ] ( auto x ) { return double ( x ) ; } ; "
2937- " const auto funcBraced<int> = [ ] ( auto x ) { return int { x } ; } ; "
2936+ const char exp[] = " constexpr auto func<double> = [ ] ( auto x ) { return double ( x ) ; } ; "
2937+ " constexpr auto funcBraced<int> = [ ] ( auto x ) { return int { x } ; } ; "
29382938 " double f ( int x ) { return func<double> ( x ) ; } "
29392939 " double fBraced ( int x ) { return funcBraced<int> ( x ) ; }" ;
29402940 ASSERT_EQUALS (exp, tok (code));
@@ -2946,8 +2946,8 @@ class TestSimplifyTemplate : public TestFixture {
29462946 " func<int>(x);\n "
29472947 " func<double>(x);\n "
29482948 " }" ;
2949- const char exp[] = " const auto func<int> = [ ] ( auto x ) { return int ( x ) ; } ; "
2950- " const auto func<double> = [ ] ( auto x ) { return double ( x ) ; } ; "
2949+ const char exp[] = " constexpr auto func<int> = [ ] ( auto x ) { return int ( x ) ; } ; "
2950+ " constexpr auto func<double> = [ ] ( auto x ) { return double ( x ) ; } ; "
29512951 " void foo ( ) { "
29522952 " func<int> ( x ) ; "
29532953 " func<double> ( x ) ; "
@@ -3084,19 +3084,19 @@ class TestSimplifyTemplate : public TestFixture {
30843084 " a<int> c ; "
30853085 " template < typename d > "
30863086 " template < typename b > "
3087- " const decltype ( auto ) a < d > :: operator() ( b && ) const { } "
3087+ " constexpr decltype ( auto ) a < d > :: operator() ( b && ) const { } "
30883088 " struct a<int> { "
3089- " template < typename b > const decltype ( auto ) operator() ( b && ) const ; "
3089+ " template < typename b > constexpr decltype ( auto ) operator() ( b && ) const ; "
30903090 " } ;" ;
30913091 const char act[] = " struct a<int> ; "
30923092 " a<int> c ; "
30933093 " template < typename d > "
30943094 " template < typename b > "
3095- " const decltype ( auto ) a < d > :: operator() ( b && ) const { } "
3095+ " constexpr decltype ( auto ) a < d > :: operator() ( b && ) const { } "
30963096 " struct a<int> { "
3097- " template < typename b > const decltype ( auto ) operator() ( b && ) const ; "
3097+ " template < typename b > constexpr decltype ( auto ) operator() ( b && ) const ; "
30983098 " } ; "
3099- " const decltype ( auto ) a<int> :: operator() ( b && ) const { }" ;
3099+ " constexpr decltype ( auto ) a<int> :: operator() ( b && ) const { }" ;
31003100 TODO_ASSERT_EQUALS (exp, act, tok (code));
31013101 }
31023102 {
@@ -3270,7 +3270,7 @@ class TestSimplifyTemplate : public TestFixture {
32703270 " return foo<TrueFalse>();\n "
32713271 " }" ;
32723272 const char exp[] = " struct TrueFalse { "
3273- " static const bool v ( ) { return true ; } "
3273+ " static constexpr bool v ( ) { return true ; } "
32743274 " } ; "
32753275 " int global ; "
32763276 " int foo<TrueFalse> ( ) ; "
@@ -3538,11 +3538,11 @@ class TestSimplifyTemplate : public TestFixture {
35383538 " static_assert(!e<f<char>>());\n "
35393539 " }" ;
35403540 const char exp[] = " namespace a { "
3541- " const bool e<f<char>> ( ) ; "
3541+ " constexpr bool e<f<char>> ( ) ; "
35423542 " class f<char> ; "
35433543 " static_assert ( ! e<f<char>> ( ) ) ; } "
35443544 " class a :: f<char> { f<char> ( a :: f < b :: d > ) ; } ; "
3545- " const bool a :: e<f<char>> ( ) { return false ; }" ;
3545+ " constexpr bool a :: e<f<char>> ( ) { return false ; }" ;
35463546 ASSERT_EQUALS (exp, tok (code));
35473547 }
35483548 }
@@ -3584,7 +3584,7 @@ class TestSimplifyTemplate : public TestFixture {
35843584 " using A3 = enum B3 {b = 0;};\n "
35853585 " A3<int> a3;" ;
35863586 const char exp[] = " template < int N > "
3587- " using A1 = struct B1 { static const auto value = N ; } ; "
3587+ " using A1 = struct B1 { static auto constexpr value = N ; } ; "
35883588 " A1 < 0 > a1 ; "
35893589 " template < class T > "
35903590 " using A2 = struct B2 { void f ( T ) { } } ; "
@@ -4807,7 +4807,7 @@ class TestSimplifyTemplate : public TestFixture {
48074807
48084808 // both of these should work but in cppcheck 2.1 only the first option will work (ticket #9843)
48094809 {
4810- const std::string expected = " template < long Num > const bool foo < bar < Num > > = true ;" ;
4810+ const std::string expected = " template < long Num > constexpr bool foo < bar < Num > > = true ;" ;
48114811 ASSERT_EQUALS (expected,
48124812 tok (" template <long Num>\n "
48134813 " constexpr bool foo<bar<Num> > = true;\n " ));
@@ -5974,28 +5974,28 @@ class TestSimplifyTemplate : public TestFixture {
59745974 {
59755975 const char code[] = " template<class T> constexpr T pi = T(3.1415926535897932385L);\n "
59765976 " float x = pi<float>;" ;
5977- const char expected[] = " const float pi<float> = float ( 3.1415926535897932385L ) ; "
5977+ const char expected[] = " constexpr float pi<float> = float ( 3.1415926535897932385L ) ; "
59785978 " float x ; x = pi<float> ;" ;
59795979 ASSERT_EQUALS (expected, tok (code));
59805980 }
59815981 {
59825982 const char code[] = " template<class> constexpr float pi = float(3.1415926535897932385L);\n "
59835983 " float x = pi<float>;" ;
5984- const char expected[] = " const float pi<float> = float ( 3.1415926535897932385L ) ; "
5984+ const char expected[] = " constexpr float pi<float> = float ( 3.1415926535897932385L ) ; "
59855985 " float x ; x = pi<float> ;" ;
59865986 ASSERT_EQUALS (expected, tok (code));
59875987 }
59885988 {
59895989 const char code[] = " template<class T = float> constexpr T pi = T(3.1415926535897932385L);\n "
59905990 " float x = pi<float>;" ;
5991- const char expected[] = " const float pi<float> = float ( 3.1415926535897932385L ) ; "
5991+ const char expected[] = " constexpr float pi<float> = float ( 3.1415926535897932385L ) ; "
59925992 " float x ; x = pi<float> ;" ;
59935993 ASSERT_EQUALS (expected, tok (code));
59945994 }
59955995 {
59965996 const char code[] = " template<class T = float> constexpr T pi = T(3.1415926535897932385L);\n "
59975997 " float x = pi<>;" ;
5998- const char expected[] = " const float pi<float> = float ( 3.1415926535897932385L ) ; "
5998+ const char expected[] = " constexpr float pi<float> = float ( 3.1415926535897932385L ) ; "
59995999 " float x ; x = pi<float> ;" ;
60006000 ASSERT_EQUALS (expected, tok (code));
60016001 }
@@ -6005,35 +6005,35 @@ class TestSimplifyTemplate : public TestFixture {
60056005 {
60066006 const char code[] = " template<class T, int N> constexpr T foo = T(N*N);\n "
60076007 " float x = foo<float,7>;" ;
6008- const char expected[] = " const float foo<float,7> = float ( 49 ) ; "
6008+ const char expected[] = " constexpr float foo<float,7> = float ( 49 ) ; "
60096009 " float x ; x = foo<float,7> ;" ;
60106010 ASSERT_EQUALS (expected, tok (code));
60116011 }
60126012 {
60136013 const char code[] = " template<class,int> constexpr float foo = float(7);\n "
60146014 " float x = foo<float,7>;" ;
6015- const char expected[] = " const float foo<float,7> = float ( 7 ) ; "
6015+ const char expected[] = " constexpr float foo<float,7> = float ( 7 ) ; "
60166016 " float x ; x = foo<float,7> ;" ;
60176017 ASSERT_EQUALS (expected, tok (code));
60186018 }
60196019 {
60206020 const char code[] = " template<class T = float, int N = 7> constexpr T foo = T(7);\n "
60216021 " double x = foo<double, 14>;" ;
6022- const char expected[] = " const double foo<double,14> = double ( 7 ) ; "
6022+ const char expected[] = " constexpr double foo<double,14> = double ( 7 ) ; "
60236023 " double x ; x = foo<double,14> ;" ;
60246024 ASSERT_EQUALS (expected, tok (code));
60256025 }
60266026 {
60276027 const char code[] = " template<class T = float, int N = 7> constexpr T foo = T(7);\n "
60286028 " float x = foo<>;" ;
6029- const char expected[] = " const float foo<float,7> = float ( 7 ) ; "
6029+ const char expected[] = " constexpr float foo<float,7> = float ( 7 ) ; "
60306030 " float x ; x = foo<float,7> ;" ;
60316031 ASSERT_EQUALS (expected, tok (code));
60326032 }
60336033 {
60346034 const char code[] = " template<class T = float, int N = 7> constexpr T foo = T(7);\n "
60356035 " double x = foo<double>;" ;
6036- const char expected[] = " const double foo<double,7> = double ( 7 ) ; "
6036+ const char expected[] = " constexpr double foo<double,7> = double ( 7 ) ; "
60376037 " double x ; x = foo<double,7> ;" ;
60386038 ASSERT_EQUALS (expected, tok (code));
60396039 }
0 commit comments