Skip to content

Commit

Permalink
Fix 12371: C++20: Requires clause on a constructor (#5972)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfultz2 committed Feb 17, 2024
1 parent 95235ca commit 20b3792
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6344,7 +6344,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, "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(), ":;{"))
Expand Down
7 changes: 7 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ class TestTokenizer : public TestFixture {
TEST_CASE(checkRefQualifiers);
TEST_CASE(checkConditionBlock);
TEST_CASE(checkUnknownCircularVar);
TEST_CASE(checkRequires);

// #9052
TEST_CASE(noCrash1);
Expand Down Expand Up @@ -7559,6 +7560,12 @@ class TestTokenizer : public TestFixture {
"}\n"));
}

void checkRequires()
{
ASSERT_NO_THROW(tokenizeAndStringify("template<class T, class U>\n"
"struct X { X(U) requires true {} };\n"));
}

void noCrash1() {
ASSERT_NO_THROW(tokenizeAndStringify(
"struct A {\n"
Expand Down

0 comments on commit 20b3792

Please sign in to comment.