Skip to content

Commit 91d0289

Browse files
committed
C++, add retval info field to cpp:function
1 parent 50dd03d commit 91d0289

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Features added
2121
base class
2222
* 9691: C, added new info-field ``retval``
2323
for :rst:dir:`c:function` and :rst:dir:`c:macro`.
24+
* C++, added new info-field ``retval`` for :rst:dir:`cpp:function`.
2425

2526
Bugs fixed
2627
----------

doc/usage/restructuredtext/domains.rst

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,14 +1496,23 @@ The ``cpp:namespace-pop`` directive undoes the most recent
14961496
Info field lists
14971497
~~~~~~~~~~~~~~~~~
14981498

1499-
The C++ directives support the following info fields (see also
1500-
:ref:`info-field-lists`):
1499+
All the C++ directives for declaring entities support the following
1500+
info fields (see also :ref:`info-field-lists`):
15011501

1502-
* `param`, `parameter`, `arg`, `argument`: Description of a parameter.
1503-
* `tparam`: Description of a template parameter.
1504-
* `returns`, `return`: Description of a return value.
1502+
* ``tparam``: Description of a template parameter.
1503+
1504+
The :rst:dir:`cpp:function` directive additionally supports the
1505+
following fields:
1506+
1507+
* ``param``, ``parameter``, ``arg``, ``argument``: Description of a parameter.
1508+
* ``returns``, ``return``: Description of a return value.
1509+
* ``retval``, ``retvals``: An alternative to ``returns`` for describing
1510+
the result of the function.
15051511
* `throws`, `throw`, `exception`: Description of a possibly thrown exception.
15061512

1513+
.. versionadded:: 4.3
1514+
The ``retval`` field type.
1515+
15071516
.. _cpp-roles:
15081517

15091518
Cross-referencing

sphinx/domains/cpp.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6934,18 +6934,10 @@ def _make_phony_error_name() -> ASTNestedName:
69346934
class CPPObject(ObjectDescription[ASTDeclaration]):
69356935
"""Description of a C++ language object."""
69366936

6937-
doc_field_types = [
6938-
GroupedField('parameter', label=_('Parameters'),
6939-
names=('param', 'parameter', 'arg', 'argument'),
6940-
can_collapse=True),
6937+
doc_field_types: List[Field] = [
69416938
GroupedField('template parameter', label=_('Template Parameters'),
69426939
names=('tparam', 'template parameter'),
69436940
can_collapse=True),
6944-
GroupedField('exceptions', label=_('Throws'), rolename='expr',
6945-
names=('throws', 'throw', 'exception'),
6946-
can_collapse=True),
6947-
Field('returnvalue', label=_('Returns'), has_arg=False,
6948-
names=('returns', 'return')),
69496941
]
69506942

69516943
option_spec: OptionSpec = {
@@ -7181,6 +7173,20 @@ class CPPMemberObject(CPPObject):
71817173
class CPPFunctionObject(CPPObject):
71827174
object_type = 'function'
71837175

7176+
doc_field_types = CPPObject.doc_field_types + [
7177+
GroupedField('parameter', label=_('Parameters'),
7178+
names=('param', 'parameter', 'arg', 'argument'),
7179+
can_collapse=True),
7180+
GroupedField('exceptions', label=_('Throws'), rolename='expr',
7181+
names=('throws', 'throw', 'exception'),
7182+
can_collapse=True),
7183+
GroupedField('retval', label=_('Return values'),
7184+
names=('retvals', 'retval'),
7185+
can_collapse=True),
7186+
Field('returnvalue', label=_('Returns'), has_arg=False,
7187+
names=('returns', 'return')),
7188+
]
7189+
71847190

71857191
class CPPClassObject(CPPObject):
71867192
object_type = 'class'

0 commit comments

Comments
 (0)