C++20 support: Support consteval and constinit (#4203)
Backported from LCppC.
This commit is contained in:
parent
fc6c203b0e
commit
cb382ac52c
|
@ -10940,6 +10940,7 @@ void Tokenizer::simplifyKeyword()
|
||||||
|
|
||||||
const bool c99 = isC() && mSettings->standards.c >= Standards::C99;
|
const bool c99 = isC() && mSettings->standards.c >= Standards::C99;
|
||||||
const bool cpp11 = isCPP() && mSettings->standards.cpp >= Standards::CPP11;
|
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()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
if (keywords.find(tok->str()) != keywords.end()) {
|
if (keywords.find(tok->str()) != keywords.end()) {
|
||||||
|
@ -10984,6 +10985,13 @@ void Tokenizer::simplifyKeyword()
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (cpp11) {
|
else if (cpp11) {
|
||||||
|
if (cpp20 && tok->str() == "consteval") {
|
||||||
|
tok->originalName(tok->str());
|
||||||
|
tok->str("constexpr");
|
||||||
|
} else if (cpp20 && tok->str() == "constinit") {
|
||||||
|
tok->deleteThis();
|
||||||
|
}
|
||||||
|
|
||||||
// final:
|
// final:
|
||||||
// 1) struct name final { }; <- struct is final
|
// 1) struct name final { }; <- struct is final
|
||||||
if (Token::Match(tok->previous(), "struct|class|union %type% final [:{]")) {
|
if (Token::Match(tok->previous(), "struct|class|union %type% final [:{]")) {
|
||||||
|
|
|
@ -4614,6 +4614,8 @@ private:
|
||||||
ASSERT_EQUALS("int foo ( ) { }", tok("__inline int foo ( ) { }", true));
|
ASSERT_EQUALS("int foo ( ) { }", tok("__inline int foo ( ) { }", true));
|
||||||
ASSERT_EQUALS("int foo ( ) { }", tok("__forceinline 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("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("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"));
|
||||||
ASSERT_EQUALS("int * * p ;", tok("int * __restrict__ * p;", "test.c"));
|
ASSERT_EQUALS("int * * p ;", tok("int * __restrict__ * p;", "test.c"));
|
||||||
|
|
Loading…
Reference in New Issue