summaryrefslogtreecommitdiff
path: root/tests/test_domain_cpp.py
diff options
context:
space:
mode:
authorJeremy Maitin-Shepard <jbms@google.com>2022-03-21 17:28:20 -0700
committerJakob Lykke Andersen <Jakob@caput.dk>2022-07-24 21:37:56 +0200
commitac1b0d490cd572fb048e80574e6cc8e7fed94e0a (patch)
treee14cacf53a7f5b9c50011afa03aa1446486554d1 /tests/test_domain_cpp.py
parent3c469c4258107589f35ae6612f5d7ecade97c805 (diff)
downloadsphinx-git-ac1b0d490cd572fb048e80574e6cc8e7fed94e0a.tar.gz
[C++] Support requires-clause in more places
Previously a C++20 requires-clause was only supported on `function` declarations. However, the C++ standard allows a require-clause on class/union templates, alias templates, and variable templates, and also allows a requires clause after each template parameter list, not just the final one. This moves the requiresClause to be a property of `ASTTemplateParams` rather than `ASTDeclaration` to better match the C++ grammar and allows requires clauses in many places that are supported by C++20 but were not previously allowed by Sphinx, namely: - On class templates, alias templates, and variable templates - After each template parameter list, not just the last one. - After the template parameter list in template template parameters. When encoding the id, the requires clause of the last template parameter list is treated specially in order to preserve compatibility with existing v4 ids.
Diffstat (limited to 'tests/test_domain_cpp.py')
-rw-r--r--tests/test_domain_cpp.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/test_domain_cpp.py b/tests/test_domain_cpp.py
index 3f31aaa18..97b887b9a 100644
--- a/tests/test_domain_cpp.py
+++ b/tests/test_domain_cpp.py
@@ -893,6 +893,24 @@ def test_domain_cpp_ast_requires_clauses():
{4: 'I0EIQoo1Aoo1B1CE1fvv'})
check('function', 'template<typename T> requires A && B || C and D void f()',
{4: 'I0EIQooaa1A1Baa1C1DE1fvv'})
+ check('function',
+ 'template<typename T> requires R<T> ' +
+ 'template<typename U> requires S<T> ' +
+ 'void A<T>::f() requires B',
+ {4: 'I0EIQ1RI1TEEI0EIQaa1SI1TE1BEN1AI1TE1fEvv'})
+ check('function',
+ 'template<template<typename T> requires R<T> typename X> ' +
+ 'void f()',
+ {2: 'II0EIQ1RI1TEE0E1fv', 4: 'II0EIQ1RI1TEE0E1fvv'})
+ check('type',
+ 'template<typename T> requires IsValid<T> {key}T = true_type',
+ {4: 'I0EIQ7IsValidI1TEE1T'}, key='using')
+ check('class',
+ 'template<typename T> requires IsValid<T> {key}T : Base',
+ {4: 'I0EIQ7IsValidI1TEE1T'}, key='class')
+ check('member',
+ 'template<typename T> requires IsValid<T> int Val = 7',
+ {4: 'I0EIQ7IsValidI1TEE3Val'})
def test_domain_cpp_ast_template_args():