Question

I'm using Doxygen to generate an API for my current project and happened upon some strange behavior. Basically, if I use an initialization list to set a member array in a class's constructor, Doxygen does not produce proper output.

Here's a simple test class:

#ifndef TEST_HPP
#define TEST_HPP

class TestClass {
public:
    /** Constructor Version 1 */
    TestClass() : v{0,0,0} { }

    /** Constructor Version 2 */
    // TestClass() { 
    //     v[0] = 0;
    //     v[1] = 0;
    //     v[2] = 0;
    // }
protected:
    /** my little array */
    float[3] v;
};

#endif // TEST_HPP

If I run doxygen on the file with Version 1 of the constructor, I get a relatively empty HTML file for the class with no constructor documentation and no mention of my variable v. If I comment out Version 1 and use Version 2, Doxygen properly produces documentation for the class.

I know this type of array setting is new to C++11, but is it the initialization or the fact that it's done in an initialization list? If anyone knows what causes this behavior I'd appreciate it as we use these types of initializers all over the code and I'd like to avoid sweeping changes if necessary.

Was it helpful?

Solution

Doxygen v1.7.6.1 dates back to 10th December 2011. It's old.

C++11 support was fundamentally added in v1.8.2; a bug in this support that seems to cover your case precisely (#688647 "Fixed problem parsing initializer list with C++11 style uniform types") was fixed in v1.8.3.

The changelog is your friend in researching such things.

The solution? Upgrade to acquire updates to doxygen's C++ parsing abilities.
We're on v1.8.5 these days.

OTHER TIPS

I am using Doxygen 1.8.5 from ARCH/extra, and the problem seems to still exist when it comes to empty initializer lists. Consider:

// not parsed correctly by doxygen 1.8.5
class X
{
public:
  typedef std::initializer_list<double> DoublesInitializer;
  typedef std::initializer_list<int   >    IntsInitializer;

  X(DoublesInitializer d, IntsInitializer i={}) : d_(d), i_(i) {}
  X(IntsInitializer i) : X({},i) {}

private:
  const std::list<double> d_;
  const std::list<int   > i_;
};

This is valid C++11 code, but in the Doxygen html output the appear superfluous „Public Attributes” i and i_, the first without a type, and the second with type const std::list<int>. Doxygen also believes to find „Initial value” for i, which is

{}

private:
  const std::list<double> d_

It turns out that the second constructor is the problematic one, since this works correctly:

// parsed correctly by doxygen 1.8.5
class Y
{
public:
  typedef std::initializer_list<double> DoublesInitializer;
  typedef std::initializer_list<int   >    IntsInitializer;

  Y(DoublesInitializer d, IntsInitializer i={}) : d_(d), i_(i) {}
  Y(IntsInitializer i) : Y(DoublesInitializer(),i) {}

private:
  const std::list<double> d_;
  const std::list<int   > i_;
};

If this is indeed a bug, I will re-open #688647.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top