Skip to content

Commit 20b3792

Browse files
authored
Fix 12371: C++20: Requires clause on a constructor (#5972)
1 parent 95235ca commit 20b3792

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6344,7 +6344,8 @@ void Tokenizer::removeMacrosInGlobalScope()
63446344
while (Token::Match(tok2, "%type% (") && tok2->isUpperCaseName())
63456345
tok2 = tok2->linkAt(1)->next();
63466346

6347-
if (Token::Match(tok, "%name% (") && Token::Match(tok2, "%name% *|&|::|<| %name%") && !Token::Match(tok2, "namespace|class|struct|union|private:|protected:|public:"))
6347+
if (Token::Match(tok, "%name% (") && Token::Match(tok2, "%name% *|&|::|<| %name%") &&
6348+
!Token::Match(tok2, "requires|namespace|class|struct|union|private:|protected:|public:"))
63486349
unknownMacroError(tok);
63496350

63506351
if (Token::Match(tok, "%type% (") && Token::Match(tok2, "%type% (") && !Token::Match(tok2, "noexcept|throw") && isFunctionHead(tok2->next(), ":;{"))

test/testtokenize.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ class TestTokenizer : public TestFixture {
409409
TEST_CASE(checkRefQualifiers);
410410
TEST_CASE(checkConditionBlock);
411411
TEST_CASE(checkUnknownCircularVar);
412+
TEST_CASE(checkRequires);
412413

413414
// #9052
414415
TEST_CASE(noCrash1);
@@ -7559,6 +7560,12 @@ class TestTokenizer : public TestFixture {
75597560
"}\n"));
75607561
}
75617562

7563+
void checkRequires()
7564+
{
7565+
ASSERT_NO_THROW(tokenizeAndStringify("template<class T, class U>\n"
7566+
"struct X { X(U) requires true {} };\n"));
7567+
}
7568+
75627569
void noCrash1() {
75637570
ASSERT_NO_THROW(tokenizeAndStringify(
75647571
"struct A {\n"

0 commit comments

Comments
 (0)