breathe icon indicating copy to clipboard operation
breathe copied to clipboard

"C++ declarations inside functions are not supported" crashes breathe

Open Algo-ryth-mix opened this issue 4 years ago • 3 comments

sphinx returns an empty List of nodes here:

        if parentDecl is not None and parentDecl.objectType == 'function':
            logger.warning("C++ declarations inside functions are not supported." +
                           " Parent function is " +
                           str(parentSymbol.get_full_nested_name()),
                           location=self.get_source_info())
            name = _make_phony_error_name()
            symbol = parentSymbol.add_name(name)
            env.temp_data['cpp:last_symbol'] = symbol
            return []

Line 6816 in sphinx/domains/cpp.py

This crashes breathe since it assumes that there is always at least one node here:

  		# Filter out outer class names if we are rendering a member as a part of a class content.
        rst_node = nodes[1]
        finder = NodeFinder(rst_node.document)
        rst_node.walk(finder)

        signode = finder.declarator

Line 587 in breathe/renderer/sphinxrenderer.py

I'm experiencing an issue with this here https://github.com/Args-Engine/Args-Engine/actions/runs/283078886 It has been crashing our pipeline for quite some time now, but I just now figured out what the culprit was :)

Algo-ryth-mix avatar Oct 01 '20 21:10 Algo-ryth-mix

Thanks for reporting this! I believe the quoted code is correct, but due to other problems it fails. The following reduced example triggers the problem as well: test.hpp:

namespace NS {
	template<typename T>
	struct A {
		using iterator = T;

		A(const std::pair<T, T> r);
	};

	template<typename T>
	A(std::pair<T, T>) -> A<T>;
}

index.rst:

.. doxygennamespace:: NS
	:members:
	:undoc-members:

.. doxygenstruct:: NS::A
	:members:
	:undoc-members:

The core issue is that the deduction guide is being interpreted as a function by Doxygen/Breathe and thus Sphinx first registers A as a function (specifically a constructor). Then when A::iterator is being registered it results in a warning.

(Interestingly, if you swap the two doxygen directives then Sphinx crashes (see sphinx-doc/sphinx#8270))

I couldn't find that Doxygen supports deduction guides yet. The XML I get for this one (with Doxygen 1.8.17) is

      <memberdef kind="function" id="iterator__tricks_8hpp_1a4eb15ccfaa9c84e61a2c3d48c6e4c152" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <templateparamlist>
          <param>
            <type>class T</type>
          </param>
        </templateparamlist>
        <type></type>
        <definition>args::core::iterator::pair_range</definition>
        <argsstring>(std::pair&lt; T, T &gt;) -&gt; pair_range&lt; T &gt;</argsstring>
        <name>pair_range</name>
        <param>
          <type>std::pair&lt; T, T &gt;</type>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="/redacted/Args-Engine/args/core/containers/iterator_tricks.hpp" line="29" column="5" declfile="/redacted/Args-Engine/args/core/containers/iterator_tricks.hpp" declline="29" declcolumn="5"/>
      </memberdef>

which I don't think is different from ordinary function XML.

Also, Sphinx doesn't support deduction guides yet (see now sphinx-doc/sphinx#8271),

jakobandersen avatar Oct 03 '20 12:10 jakobandersen

Thanks for taking a look, I found it fishy that sphinx complained about my struct having a declaration inside it and also being a function :), I'll try to guard the CTAD on Monday and see if that improves our ci-situation

Algo-ryth-mix avatar Oct 03 '20 12:10 Algo-ryth-mix

excluding the CTAD from doxygen does indeed get rid of this error (sorry for the late reply)

Algo-ryth-mix avatar Oct 06 '20 12:10 Algo-ryth-mix