Skip to content

Commit a0e986c

Browse files
Merge pull request sphinx-doc#9694 from jakobandersen/cpp-info-fields
C++, add retval info field
2 parents 50dd03d + a6246c1 commit a0e986c

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

CHANGES

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ Features added
1919
* #9639: autodoc: Support asynchronous generator functions
2020
* #9664: autodoc: ``autodoc-process-bases`` supports to inject reST snippet as a
2121
base class
22-
* 9691: C, added new info-field ``retval``
22+
* #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: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ The C domain (name **c**) is suited for documentation of C API.
677677
Note that you don't have to backslash-escape asterisks in the signature, as
678678
it is not parsed by the reST inliner.
679679

680-
In the description of a function you can use the following info-fields
680+
In the description of a function you can use the following info fields
681681
(see also :ref:`info-field-lists`).
682682

683683
* ``param``, ``parameter``, ``arg``, ``argument``,
@@ -723,7 +723,7 @@ The C domain (name **c**) is suited for documentation of C API.
723723
Describes a C macro, i.e., a C-language ``#define``, without the replacement
724724
text.
725725
726-
In the description of a macro you can use the same info-fields as for the
726+
In the description of a macro you can use the same info fields as for the
727727
:rst:dir:`c:function` directive.
728728
729729
.. versionadded:: 3.0
@@ -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)