File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5721,7 +5721,22 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
57215721
57225722 // if MACRO
57235723 for (Token *tok = list.front (); tok; tok = tok->next ()) {
5724- if (Token::Match (tok, " if|for|while %name% (" )) {
5724+ if (Token::simpleMatch (tok, " if consteval {" )) {
5725+ // 'if consteval { ... }' -> 'if ( __cppcheck_consteval__ ) { ... }'
5726+ Token *parTok = tok->next ();
5727+ parTok->str (" (" );
5728+ Token *evalTok = parTok->insertToken (" __cppcheck_consteval__" );
5729+ evalTok->originalName (" consteval" );
5730+ evalTok->insertToken (" )" );
5731+ } else if (Token::Match (tok, " if !|not consteval {" )) {
5732+ // 'if !consteval { ... }' / 'if not consteval { ... }' -> 'if ( ! __cppcheck_consteval__ ) { ... }'
5733+ Token *notTok = tok->next ();
5734+ notTok->insertTokenBefore (" (" );
5735+ Token *evalTok = notTok->next ();
5736+ evalTok->str (" __cppcheck_consteval__" );
5737+ evalTok->originalName (" consteval" );
5738+ evalTok->insertToken (" )" );
5739+ } else if (Token::Match (tok, " if|for|while %name% (" )) {
57255740 if (Token::simpleMatch (tok, " for each" )) {
57265741 // 'for each (x in y )' -> 'for (x : y)'
57275742 if (Token* in = Token::findsimplematch (tok->tokAt (2 ), " in" , tok->linkAt (2 )))
Original file line number Diff line number Diff line change @@ -104,6 +104,7 @@ class TestTokenizer : public TestFixture {
104104
105105 TEST_CASE (foreach); // #3690
106106 TEST_CASE (ifconstexpr);
107+ TEST_CASE (ifconsteval);
107108
108109 TEST_CASE (combineOperators);
109110
@@ -1042,6 +1043,22 @@ class TestTokenizer : public TestFixture {
10421043 filter_valueflow (errout_str ()));
10431044 }
10441045
1046+ void ifconsteval () {
1047+ ASSERT_EQUALS (" void f ( ) { if ( __cppcheck_consteval__ ) { bar ( ) ; } }" , tokenizeAndStringify (" void f() { if consteval { bar(); } }" ));
1048+ filter_valueflow (errout_str ());
1049+
1050+ ASSERT_EQUALS (" void f ( ) { if ( ! __cppcheck_consteval__ ) { bar ( ) ; } }" , tokenizeAndStringify (" void f() { if !consteval { bar(); } }" ));
1051+ filter_valueflow (errout_str ());
1052+
1053+ ASSERT_EQUALS (" void f ( ) { if ( __cppcheck_consteval__ ) { bar ( ) ; } else { baz ( ) ; } }" ,
1054+ tokenizeAndStringify (" void f() { if consteval { bar(); } else { baz(); } }" ));
1055+ filter_valueflow (errout_str ());
1056+
1057+ ASSERT_EQUALS (" constexpr bool is_runtime_evaluated ( ) noexcept ( true ) { if ( ! __cppcheck_consteval__ ) { return true ; } else { return false ; } }" ,
1058+ tokenizeAndStringify (" constexpr bool is_runtime_evaluated() noexcept { if not consteval { return true; } else { return false; } }" ));
1059+ filter_valueflow (errout_str ());
1060+ }
1061+
10451062 void combineOperators () {
10461063 ASSERT_EQUALS (" ; private: ;" , tokenizeAndStringify (" ;private:;" ));
10471064 ASSERT_EQUALS (" ; protected: ;" , tokenizeAndStringify (" ;protected:;" ));
You can’t perform that action at this time.
0 commit comments