Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unparseable C++ reference to call operator #2952

Closed
other-mickk opened this issue Sep 13, 2016 · 9 comments
Closed

Unparseable C++ reference to call operator #2952

other-mickk opened this issue Sep 13, 2016 · 9 comments

Comments

@other-mickk
Copy link
Contributor

Given the following document, with a default config:

.. default-domain:: cpp

.. class:: foo

    .. function:: void operator()(int)

        Description.

    Reference to :func:`operator()`.

Reference to :func:`foo::operator()`.

then Sphinx complains when trying to build, ultimately reporting the following:

/home/mickk/test/sphinx/source/index.rst:9: WARNING: Unparseable C++ cross-reference: 'operator'
Invalid definition: Expected identifier in nested name. [error at 8]
  operator
  --------^
/home/mickk/test/sphinx/source/index.rst:11: WARNING: Unparseable C++ cross-reference: 'foo::operator'
Invalid definition: Expected identifier in nested name. [error at 13]
  foo::operator
  -------------^

In the generated document the references won’t link. I have this behaviour on 1.4.6 and master.

@jakobandersen
Copy link
Contributor

I think this has to do with the fix_parens-functionality provided by the base role, which uses the config variable add_function_parentheses. It removes () in the end before the C++ parser gets it, and adds it to the link text for all uses of :func:.
I will make a fix as soon as possible, but I think you can work around it by adding an extra (), i.e., :func:foo::operator()()``.

@other-mickk
Copy link
Contributor Author

other-mickk commented Sep 15, 2016

Thanks for the workaround, it will do the job for now.

If it helps, I noticed I used to have some of my references as e.g. :cpp:member:foo::operator()``. This will be parsed, but nowadays Sphinx rightfully warns that I’m referring a :func: from a `:member:`, so that prompted me to change to the `:any:` role which is how I stumbled into the unparseable references.

jakobandersen added a commit that referenced this issue Jan 15, 2017
@jakobandersen
Copy link
Contributor

This should be fixed in stable now.

@jfbu
Copy link
Contributor

jfbu commented Jan 15, 2017

@jakobandersen there seems to be a problem since 00fcbfb ccd6bf4 that Sphinx own docs can not be built.

Trace log, extract:

# Sphinx version: 1.5.2+/ccd6bf4
# Python version: 3.5.2 (CPython)
# Docutils version: 0.12 release
# Jinja2 version: 2.8
# Last messages:
...
  File "/FOO/sphinx/sphinx/builders/latex.py", line 120, in write
    appendices=((docclass != 'howto') and self.config.latex_appendices or []))
  File "/FOO/sphinx/sphinx/builders/latex.py", line 168, in assemble_doctree
    self.env.resolve_references(largetree, indexfile, self)
  File "/FOO/sphinx/sphinx/environment/__init__.py", line 1053, in resolve_references
    typ, target, node, contnode)
  File "/FOO/sphinx/sphinx/domains/cpp.py", line 4586, in resolve_xref
    target, node, contnode)[0]
  File "/FOO/sphinx/sphinx/domains/cpp.py", line 4564, in _resolve_xref_inner
    if not node['refexplicit'] and declaration.objectType == 'function':
  File "/opt/miniconda3/lib/python3.5/site-packages/docutils/nodes.py", line 567, in __getitem__
    return self.attributes[key]
KeyError: 'refexplicit'

@jfbu
Copy link
Contributor

jfbu commented Jan 15, 2017

Sorry the commit I wanted to report is ccd6bf4, my working-tree corresponded to it but the index was at its parent 00fcbfb. I will edit for clarification previous message.

@jakobandersen
Copy link
Contributor

@jfbu thanks for catching that, it should be fixed now.

@jfbu
Copy link
Contributor

jfbu commented Jan 16, 2017

@jakobandersen looking at the fix and at the error log I see the latter was so precise I should have been able to understand by myself... feel dumb about making noise here ;-)

@other-mickk
Copy link
Contributor Author

A quick heads-up, I suspect the fix caused the following behaviour if a user attempts e.g. a :cpp:any:`void` reference:

WARNING: Unparseable C++ cross-reference: 'void()'
Invalid definition: Expected identifier in nested name, got keyword: void [error at 4]
  void()
  ----^

In comparison a user attempting to refer to :cpp:type:`void` will see this as a result:

WARNING: Unparseable C++ cross-reference: 'void'
Invalid definition: Expected identifier in nested name, got keyword: void [error at 4]
  void
  ----^

I don't know if that merits another issue.

@jakobandersen
Copy link
Contributor

Thanks, it should be fixed for almost all cases in stable now.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants