From 9dd584288a377b1e19766780c48000547defbff2 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 11 Feb 2024 19:55:07 -0600 Subject: [PATCH 1/2] Fix 12371: C++20: Requires clause on a constructor --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 6bdee6618dc..960cc479d81 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6342,7 +6342,7 @@ void Tokenizer::removeMacrosInGlobalScope() while (Token::Match(tok2, "%type% (") && tok2->isUpperCaseName()) tok2 = tok2->linkAt(1)->next(); - if (Token::Match(tok, "%name% (") && Token::Match(tok2, "%name% *|&|::|<| %name%") && !Token::Match(tok2, "namespace|class|struct|union|private:|protected:|public:")) + if (Token::Match(tok, "%name% (") && Token::Match(tok2, "%name% *|&|::|<| %name%") && !Token::Match(tok2, "requires|namespace|class|struct|union|private:|protected:|public:")) unknownMacroError(tok); if (Token::Match(tok, "%type% (") && Token::Match(tok2, "%type% (") && !Token::Match(tok2, "noexcept|throw") && isFunctionHead(tok2->next(), ":;{")) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 03b780eab47..88c997609ee 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -409,6 +409,7 @@ class TestTokenizer : public TestFixture { TEST_CASE(checkRefQualifiers); TEST_CASE(checkConditionBlock); TEST_CASE(checkUnknownCircularVar); + TEST_CASE(checkRequires); // #9052 TEST_CASE(noCrash1); @@ -7559,6 +7560,12 @@ class TestTokenizer : public TestFixture { "}\n")); } + void checkRequires() + { + ASSERT_NO_THROW(tokenizeAndStringify("template\n" + "struct X { X(U) requires true {} };\n")); + } + void noCrash1() { ASSERT_NO_THROW(tokenizeAndStringify( "struct A {\n" From 52cee634133a1cb7f8afb76ce2caf5bf0627bd14 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 11 Feb 2024 19:56:06 -0600 Subject: [PATCH 2/2] Format --- lib/tokenize.cpp | 3 ++- test/testtokenize.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 960cc479d81..4d9b81559ba 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6342,7 +6342,8 @@ void Tokenizer::removeMacrosInGlobalScope() while (Token::Match(tok2, "%type% (") && tok2->isUpperCaseName()) tok2 = tok2->linkAt(1)->next(); - if (Token::Match(tok, "%name% (") && Token::Match(tok2, "%name% *|&|::|<| %name%") && !Token::Match(tok2, "requires|namespace|class|struct|union|private:|protected:|public:")) + if (Token::Match(tok, "%name% (") && Token::Match(tok2, "%name% *|&|::|<| %name%") && + !Token::Match(tok2, "requires|namespace|class|struct|union|private:|protected:|public:")) unknownMacroError(tok); if (Token::Match(tok, "%type% (") && Token::Match(tok2, "%type% (") && !Token::Match(tok2, "noexcept|throw") && isFunctionHead(tok2->next(), ":;{")) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 88c997609ee..6fa10173b07 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7563,7 +7563,7 @@ class TestTokenizer : public TestFixture { void checkRequires() { ASSERT_NO_THROW(tokenizeAndStringify("template\n" - "struct X { X(U) requires true {} };\n")); + "struct X { X(U) requires true {} };\n")); } void noCrash1() {