diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index 7dd1d0c03..882c8275f 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -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" diff --git a/tests/test_domain_cpp.py b/tests/test_domain_cpp.py index 9159b1851..c88111e89 100644 --- a/tests/test_domain_cpp.py +++ b/tests/test_domain_cpp.py @@ -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 requires A && B || C and D void f()', {4: 'I0EIQooaa1A1Baa1C1DE1fvv'}) check('function',