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

Support for parameterized GNU style attributes on C++ code. #7853

Closed
obra opened this issue Jun 19, 2020 · 2 comments · Fixed by #7854
Closed

Support for parameterized GNU style attributes on C++ code. #7853

obra opened this issue Jun 19, 2020 · 2 comments · Fixed by #7854
Assignees
Labels
domains:cpp type:enhancement enhance or introduce a new feature
Milestone

Comments

@obra
Copy link

obra commented Jun 19, 2020

Hi folks.

My C++ codebase uses GNU attributes for code like

__attribute__ ((optimize(3))) void readMatrix(void)

Unfortunately, it looks like Sphinx doesn't support them.

Exception occurred:
  File "/usr/local/lib/python3.7/site-packages/sphinx/domains/cpp.py", line 6099, in _parse_type
    raise self._make_multi_error(prevErrors, header)
sphinx.util.cfamily.DefinitionError: Error when parsing function declaration.
If the function has no return type:
  Invalid C++ declaration: Parameterized GNU style attribute not yet supported. [error at 25]
    __attribute__ ((optimize(3))) void readMatrix(void)
    -------------------------^
If the function has a return type:
  Invalid C++ declaration: Parameterized GNU style attribute not yet supported. [error at 25]
    __attribute__ ((optimize(3))) void readMatrix(void)
    -------------------------^

I'm running Sphinx 3.1.1, though this functionality doesn't appear to have changed in 4.

I tried to get clever with the custom attribute support you offer, but can't seem to get that to work either.

cpp_id_attributes = ["aligned","packed","weak","always_inline","noinline","no-unroll-loops","__attribute__((optimize(3)))"]
cpp_paren_attributes = ["optimize","__aligned__","section","deprecated"]

Is there a right way to do this? I'd honestly be fine having the attributes stripped entirely for doc generation if there isn't another option.

Even though I'm bumping up against a sharp edge, I really appreciate Sphinx. Thanks so much for making a useful tool.

@jakobandersen
Copy link
Contributor

I tried to get clever with the custom attribute support you offer, but can't seem to get that to work either.

Unfortunately, Sphinx is cleaver enough to recognize that it definitely is a GNU style attribute, so the custom entries are not even tried.

Is there a right way to do this?

Yes, upgrade to v3.2 once it has been released :-), and until then use the 3.x branch where I added the support.

@obra
Copy link
Author

obra commented Jun 20, 2020

Awesome. Thank you so much!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
domains:cpp type:enhancement enhance or introduce a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants