breathe
breathe copied to clipboard
Parens in return type template are dropped, failing Sphinx
This C++ function is not parsed correctly by Breathe:
// One of the opening parens is dropped by Breathe.
template <typename T>
MyTemplate<decltype(std::declval<T>())> broken_func();
This is the error message:
WARNING: Error when parsing function declaration.
If the function has no return type:
Error in declarator or parameters-and-qualifiers
Main error:
Invalid C++ declaration: Expecting "(" in parameters-and-qualifiers. [error at 31]
template<typename T> MyTemplate< decltype(std::declval< T >))> broken_func ()
-------------------------------^
Potential other error:
Error in parsing template argument list.
If type argument:
Invalid C++ declaration: Expected "...>", ">" or "," in template argument list. [error at 60]
template<typename T> MyTemplate< decltype(std::declval< T >))> broken_func ()
------------------------------------------------------------^
If non-type argument:
Error in postfix expression, expected primary expression or type.
If primary expression:
Invalid C++ declaration: Expected identifier in nested name, got keyword: decltype [error at 41]
template<typename T> MyTemplate< decltype(std::declval< T >))> broken_func ()
-----------------------------------------^
If type:
Invalid C++ declaration: Expecting '(' or '{' after type in cast expression. [error at 60]
template<typename T> MyTemplate< decltype(std::declval< T >))> broken_func ()
------------------------------------------------------------^
If the function has a return type:
Error in declarator or parameters-and-qualifiers
If pointer to member declarator:
Main error:
Invalid C++ declaration: Expected identifier in nested name. [error at 31]
template<typename T> MyTemplate< decltype(std::declval< T >))> broken_func ()
-------------------------------^
Potential other error:
Error in parsing template argument list.
If type argument:
Invalid C++ declaration: Expected "...>", ">" or "," in template argument list. [error at 60]
template<typename T> MyTemplate< decltype(std::declval< T >))> broken_func ()
------------------------------------------------------------^
If non-type argument:
Error in postfix expression, expected primary expression or type.
If primary expression:
Invalid C++ declaration: Expected identifier in nested name, got keyword: decltype [error at 41]
template<typename T> MyTemplate< decltype(std::declval< T >))> broken_func ()
-----------------------------------------^
If type:
Invalid C++ declaration: Expecting '(' or '{' after type in cast expression. [error at 60]
template<typename T> MyTemplate< decltype(std::declval< T >))> broken_func ()
------------------------------------------------------------^
If declarator-id:
Invalid C++ declaration: Expected identifier in nested name. [error at 31]
template<typename T> MyTemplate< decltype(std::declval< T >))> broken_func ()
-------------------------------^
I created a minimal working example to reproduce this issue here:
https://github.com/nilsleiffischer/sphinx-bugs/tree/master/issue_breathe_templates
This is my environment:
- Python 3.8.6
- Breathe (breathe-apidoc) 4.27.0
- sphinx-build 3.5.3
- Doxygen 1.8.17
@nilsleiffischer I am fairly sure this error is over at the Sphinx, to be specific in Sphinx's C/C++ domain, see https://github.com/sphinx-doc/sphinx/blob/3.x/sphinx/util/cfamily.py#L285. Can you verify this based upon the full traceback?
@vermeeren I might be misinterpreting this, but here's why I determined the issue is in Breathe, not in Sphinx: I added this commit https://github.com/nilsleiffischer/sphinx-bugs/commit/698e3b2689eafc0b3061f8921c336e00a081f0fe to the minimal working example https://github.com/nilsleiffischer/sphinx-bugs/tree/master/issue_breathe_templates. It shows that Sphinx manages to parse this snippet fine:
.. cpp:function::
template <typename T> MyTemplate<decltype(std::declval<T>())> broken_func();
Sphinx manages to parse this function. It breaks when parsing it with
Breathe:
.. autodoxygenindex::
Please let me know if there's any more info I can provide here to help debug the issue. I edited the issue description to include the full traceback.
Actually, I think this is a Doxygen issue. We would need to check the XML to be sure, but it looks very similar to #624 and #611, as decltype
is involved in all three cases.
@jakobandersen Yes I think you're right! I filed the issue here: https://github.com/doxygen/doxygen/issues/8465