diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 090ded5a7..06ca1c146 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -10940,6 +10940,7 @@ void Tokenizer::simplifyKeyword() const bool c99 = isC() && mSettings->standards.c >= Standards::C99; const bool cpp11 = isCPP() && mSettings->standards.cpp >= Standards::CPP11; + const bool cpp20 = isCPP() && mSettings->standards.cpp >= Standards::CPP20; for (Token *tok = list.front(); tok; tok = tok->next()) { if (keywords.find(tok->str()) != keywords.end()) { @@ -10984,6 +10985,13 @@ void Tokenizer::simplifyKeyword() } else if (cpp11) { + if (cpp20 && tok->str() == "consteval") { + tok->originalName(tok->str()); + tok->str("constexpr"); + } else if (cpp20 && tok->str() == "constinit") { + tok->deleteThis(); + } + // final: // 1) struct name final { }; <- struct is final if (Token::Match(tok->previous(), "struct|class|union %type% final [:{]")) { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index f82a778ba..82f0069c6 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -4614,6 +4614,8 @@ private: ASSERT_EQUALS("int foo ( ) { }", tok("__inline int foo ( ) { }", true)); ASSERT_EQUALS("int foo ( ) { }", tok("__forceinline int foo ( ) { }", true)); ASSERT_EQUALS("constexpr int foo ( ) { }", tok("constexpr int foo() { }", true)); + ASSERT_EQUALS("constexpr int foo ( ) { }", tok("consteval int foo() { }", true)); + ASSERT_EQUALS("int x ; x = 0 ;", tok("constinit int x = 0;", true)); ASSERT_EQUALS("void f ( ) { int final [ 10 ] ; }", tok("void f() { int final[10]; }", true)); ASSERT_EQUALS("int * p ;", tok("int * __restrict p;", "test.c")); ASSERT_EQUALS("int * * p ;", tok("int * __restrict__ * p;", "test.c"));