[C++] Allow trailing requires-clause on constructors

This commit is contained in:
Jeremy Maitin-Shepard 2022-03-27 11:02:27 -07:00 committed by Jakob Lykke Andersen
parent 9694aa5a26
commit 33f5474951
2 changed files with 10 additions and 1 deletions

View File

@ -6537,7 +6537,14 @@ class DefinitionParser(BaseParser):
declSpecs = self._parse_decl_specs(outer=outer, typed=False)
decl = self._parse_declarator(named=True, paramMode=outer,
typed=False)
self.assert_end(allowSemicolon=True)
must_end = True
if outer == 'function':
# Allow trailing requires on constructors
self.skip_ws()
if re.compile(r'requires\b').match(self.definition, self.pos):
must_end = False
if must_end:
self.assert_end(allowSemicolon=True)
except DefinitionError as exUntyped:
if outer == 'type':
desc = "If just a name"

View File

@ -893,6 +893,8 @@ def test_domain_cpp_ast_requires_clauses():
{4: 'I0EIQoo1Aoo1B1CE1fvv'})
check('function', 'void f() requires A || B || C',
{4: 'IQoo1Aoo1B1CE1fv'})
check('function', 'Foo() requires A || B || C',
{4: 'IQoo1Aoo1B1CE3Foov'})
check('function', 'template<typename T> requires A && B || C and D void f()',
{4: 'I0EIQooaa1A1Baa1C1DE1fvv'})
check('function',