AlwaysLearning AlwaysLearning - 1 month ago 15
C++ Question

Doxygen error: Found ';' while parsing initializer list

Doxygen 1.8.11 is choking on the following definition, which I simplified as much as I could without losing the warning message:

template <class T>
struct MySpecialization<T, void_t<decltype(std::declval<T>().foo(
std::declval<double>()))>> : std::true_type {};


The warning is:

warning: Found ';' while parsing initializer list! (doxygen could be confused by a macro call without semicolon)


Interestingly, Doxygen is fine with the following:

template <class T>
struct MySpecialization<T, void_t<decltype(std::declval<T>().foo())>> : std::true_type {};


which is basically the same definition without an argument to
foo
.

I would very much appreciate a workaround. In the worst case, I would like to somehow cause Doxygen to ignore this definition.

Answer

The answer is in the docs. Use doxygen's \cond and \endcond commands or use preprocessor defines.

/// \cond NOPE
template <class T>
struct MySpecialization<T, void_t<decltype(std::declval<T>().foo(
                             std::declval<double>()))>> : std::true_type {};
/// \endcond

With preprocessor defines you can add Doxygen-friendly definition. For example, the Qt project does this.

#ifdef DOXYGEN_WORKING
template <class T>
struct MySpecialization<T, something_that_doxygen_understands> : std::true_type {};
#else
template <class T>
struct MySpecialization<T, void_t<decltype(std::declval<T>().foo(
                             std::declval<double>()))>> : std::true_type {};
#endif

and add PREDEFINED = DOXYGEN_WORKING to your config file.

Comments