Parser; Partial C++20 support, explicit(bool)

This commit is contained in:
Daniel Marjamäki 2021-05-09 18:47:02 +02:00
parent 32b28d568f
commit 3b37c14b3c
2 changed files with 27 additions and 0 deletions

View File

@ -3693,6 +3693,16 @@ void TemplateSimplifier::simplifyTemplates(
if (end)
Token::eraseTokens(tok, end);
}
// explicit(bool)
for (Token *tok = mTokenList.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "explicit (")) {
bool isFalse = Token::simpleMatch(tok->tokAt(2), "false )");
Token::eraseTokens(tok, tok->linkAt(1)->next());
if (isFalse)
tok->deleteThis();
}
}
}
mTokenizer->calculateScopes();

View File

@ -295,6 +295,9 @@ private:
TEST_CASE(requires3);
TEST_CASE(requires4);
TEST_CASE(requires5);
TEST_CASE(explicitBool1);
TEST_CASE(explicitBool2);
}
std::string tok(const char code[], bool debugwarnings = false, Settings::PlatformType type = Settings::Native) {
@ -6146,6 +6149,20 @@ private:
const char expected[] = "int add<int> ( int a , int b ) ; add<int> ( 123 , 456 ) ; int add<int> ( int a , int b ) { return a + b ; }";
ASSERT_EQUALS(expected, tok(code));
}
void explicitBool1() {
Settings settings;
settings.standards.cpp = Standards::CPP20;
const char code[] = "class Fred { explicit(true) Fred(int); };";
ASSERT_EQUALS("class Fred { explicit Fred ( int ) ; } ;", tok(code));
}
void explicitBool2() {
Settings settings;
settings.standards.cpp = Standards::CPP20;
const char code[] = "class Fred { explicit(false) Fred(int); };";
ASSERT_EQUALS("class Fred { Fred ( int ) ; } ;", tok(code));
}
};
REGISTER_TEST(TestSimplifyTemplate)