Skip to content

Commit

Permalink
C++, add support for overload-specific references.
Browse files Browse the repository at this point in the history
The "any" and "func" roles now accepts full function declarations.

Fixes sphinx-doc#1552
  • Loading branch information
jakobandersen committed Aug 18, 2018
1 parent 3348b92 commit 1c035d7
Show file tree
Hide file tree
Showing 3 changed files with 282 additions and 135 deletions.
18 changes: 11 additions & 7 deletions CHANGES
Expand Up @@ -167,13 +167,17 @@ Features added
* #4785: napoleon: Add strings to translation file for localisation
* #4927: Display a warning when invalid values are passed to linenothreshold
option of highlight directive
* C++, add a ``cpp:texpr`` role as a sibling to ``cpp:expr``.
* C++, add support for unions.
* C++, add support for anonymous entities using names staring with ``@``.
Fixes #3593 and #2683.
* #5147: C++, add support for (most) character literals.
* C++, cross-referencing entities inside primary templates is supported,
and now properly documented.
* C++:

- Add a ``cpp:texpr`` role as a sibling to ``cpp:expr``.
- Add support for unions.
- #3593, #2683: add support for anonymous entities using names staring with ``@``.
- #5147: add support for (most) character literals.
- Cross-referencing entities inside primary templates is supported,
and now properly documented.
- #1552: add new cross-referencing format for ``cpp:any`` and ``cpp:func`` roles,
for referencing specific function overloads.

* #3606: MathJax should be loaded with async attribute
* html: Output ``canonical_url`` metadata if :confval:`html_baseurl` set (refs:
#4193)
Expand Down
42 changes: 34 additions & 8 deletions doc/usage/restructuredtext/domains.rst
Expand Up @@ -1005,20 +1005,46 @@ These roles link to the given declaration types:
When a custom title is not needed it may be useful to use the roles for inline expressions,
:rst:role:`cpp:expr` and :rst:role:`cpp:texpr`, where angle brackets do not need escaping.

.. admonition:: Note on References to Overloaded Functions

It is currently impossible to link to a specific version of an overloaded
function. Currently the C++ domain is the first domain that has basic
support for overloaded functions and until there is more data for comparison
we don't want to select a bad syntax to reference a specific overload.
Currently Sphinx will link to the first overloaded version of the function.

Declarations without template parameters and template arguments
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For linking to non-templated declarations the name must be a nested name, e.g.,
``f`` or ``MyClass::f``.


Overloaded (member) functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

When a (member) function is referenced using just its name, the reference
will point to an arbitrary matching overload.
The :rst:role:`cpp:any` and :rst:role:`cpp:func` roles will an alternative
format, which simply is a complete function declaration.
This will resolve to the exact matching overload.
As example, consider the following class declaration:

.. cpp:namespace-push:: overload_example
.. cpp:class:: C

.. cpp:function:: void f(double d) const
.. cpp:function:: void f(double d)
.. cpp:function:: void f(int i)
.. cpp:function:: void f()

References using the :rst:role:`cpp:func` role:

- Arbitrary overload: ``C::f``, :cpp:func:`C::f`
- Also arbitrary overload: ``C::f()``, :cpp:func:`C::f()`
- Specific overload: ``void C::f()``, :cpp:func:`void C::f()`
- Specific overload: ``void C::f(int)``, :cpp:func:`void C::f(int)`
- Specific overload: ``void C::f(double)``, :cpp:func:`void C::f(double)`
- Specific overload: ``void C::f(double) const``, :cpp:func:`void C::f(double) const`

Note that the :confval:`add_function_parentheses` configuration variable
does not influence specific overload references.

.. cpp:namespace-pop::


Templated declarations
^^^^^^^^^^^^^^^^^^^^^^

Expand Down

0 comments on commit 1c035d7

Please sign in to comment.