breathe icon indicating copy to clipboard operation
breathe copied to clipboard

Parens in return type template are dropped, failing Sphinx

Open nilsvu opened this issue 3 years ago • 4 comments

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

nilsvu avatar Mar 21 '21 19:03 nilsvu

@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 avatar Mar 29 '21 02:03 vermeeren

@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.

nilsvu avatar Mar 29 '21 08:03 nilsvu

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 avatar Mar 29 '21 08:03 jakobandersen

@jakobandersen Yes I think you're right! I filed the issue here: https://github.com/doxygen/doxygen/issues/8465

nilsvu avatar Mar 29 '21 12:03 nilsvu