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

Duplicate declaration when using nested classes #514

Open
5p4k opened this issue Apr 26, 2020 · 1 comment
Open

Duplicate declaration when using nested classes #514

5p4k opened this issue Apr 26, 2020 · 1 comment

Comments

@5p4k
Copy link

5p4k commented Apr 26, 2020

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.

@jakobandersen
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants