From 3b37c14b3ce933927f2443152a16ea1131e4755c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 9 May 2021 18:47:02 +0200 Subject: [PATCH] Parser; Partial C++20 support, explicit(bool) --- lib/templatesimplifier.cpp | 10 ++++++++++ test/testsimplifytemplate.cpp | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 581a38efc..5f63414b1 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -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(); diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 8dafeaac5..5ec0e6b15 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -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 a , int b ) ; add ( 123 , 456 ) ; int add ( 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)