breathe icon indicating copy to clipboard operation
breathe copied to clipboard

Duplicate declaration when using nested classes

Open 5p4k opened this issue 4 years ago • 1 comments

This occurs when forward-declaring a nested class and then implementing it somewhere else, e.g. the following code

/** @brief This class has a nested class defined elsewhere
 */
class parent {
public:
    class nested;
};

/** @brief The nested class
 * @note Every member of this class will raise a DUPLICATE warning
 */
class parent::nested {
public:
    /** @brief Raises a DUPLICATE warning
     */
    inline void this_method_will_be_duplicate() const {}
};

produces the following warnings:

./respiration_issues/docs/api/classnested_1_1parent_1_1nested.rst:19: WARNING: Duplicate declaration, nested::parent::nested
./respiration_issues/docs/api/classnested_1_1parent_1_1nested.rst:19: WARNING: Duplicate declaration, void this_method_will_be_duplicate () const

I tried with master version of Sphinx and Breathe (through Exhale), but this still persists. It also persists when using PR 512.

I have an Exhale-based project here that containes the example above to reproduce.

5p4k avatar Apr 26 '20 16:04 5p4k

The warnings seems to be correct. There are two rst files (generated by Exhale?) of interest:

  • api/classnested_1_1parent.rst for the parent class.
  • api/classnested_1_1parent_1_1nested.rst for the nested class. However, the parent file already contains the declarations for the nested class (recursively), so the declarations in the second file become duplicates (or the other way around depending on the order the input files are processed).

What Sphinx sees can be seen in the log output below (generated using config breathe_debug_trace_directives = True with Breathe from https://github.com/jakobandersen/breathe/tree/debug_config):

reading sources... [ 12%] api/classnested_1_1parent
Running directive: .. cpp:class::  nested::parent
  Running directive: .. cpp:class::  nested
    Running directive: .. cpp:function::  void this_method_will_be_duplicate () const
reading sources... [ 14%] api/classnested_1_1parent_1_1nested
Running directive: .. cpp:class::  nested::parent::nested
  Running directive: .. cpp:function::  void this_method_will_be_duplicate () const

jakobandersen avatar May 22 '20 10:05 jakobandersen