diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index 2bcdf4432d3..d9ce70623e4 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -6983,7 +6983,7 @@ def parse_declaration(self, objectType: str, directiveType: str) -> ASTDeclarati if self.match(_visibility_re): visibility = self.matched_text - if objectType in ('type', 'concept', 'member', 'function', 'class'): + if objectType in ('type', 'concept', 'member', 'function', 'class', 'union'): templatePrefix = self._parse_template_declaration_prefix(objectType) if objectType == 'type': diff --git a/tests/test_domain_cpp.py b/tests/test_domain_cpp.py index 977426c8029..05a111e3999 100644 --- a/tests/test_domain_cpp.py +++ b/tests/test_domain_cpp.py @@ -917,6 +917,9 @@ def test_domain_cpp_ast_requires_clauses(): check('class', 'template requires IsValid {key}T : Base', {4: 'I0EIQ7IsValidI1TEE1T'}, key='class') + check('union', + 'template requires IsValid {key}T', + {4: 'I0EIQ7IsValidI1TEE1T'}, key='union') check('member', 'template requires IsValid int Val = 7', {4: 'I0EIQ7IsValidI1TEE3Val'})