【发布时间】:2016-01-08 08:38:37
【问题描述】:
我有一个实现欧几里得算法(优化版本)的简单递归模板。 Doxygen 抱怨它:
/usr/home/kamikaze/stark/Yggdrasil/src/units/Units.hpp:335: warning: Detected potential recursive class relation between class units::euclid and base class units::euclid< Rhs, Lhs%Rhs >!
/usr/home/kamikaze/stark/Yggdrasil/src/units/Units.hpp:335: warning: Detected potential recursive class relation between class units::euclid and base class euclid< Rhs, Lhs%Rhs >!
/usr/home/kamikaze/stark/Yggdrasil/src/units/Units.hpp:335: warning: Detected potential recursive class relation between class units::euclid and base class units::euclid< Rhs, Lhs%Rhs >!
/usr/home/kamikaze/stark/Yggdrasil/src/units/Units.hpp:335: warning: Detected potential recursive class relation between class units::euclid and base class euclid< Rhs, Lhs%Rhs >!
我很惊讶为什么这是一个投诉/警告。我认为递归类型是常见且合法的。它也是许多递归模板之一,但只有一个 doxygen 抱怨。 令我惊讶的是,我只发现了 doxygen 错误检测递归的类似问题。
如果你有兴趣,这里是代码:
/**
* Implements Euclid's algorithm to find the GCD between two integers.
*
* @tparam Lhs,Rhs
* The values to get the GCD for
*/
template <int Lhs, int Rhs>
struct euclid : euclid<Rhs, Lhs % Rhs> {
};
/**
* Terminates Euclid's algorithm.
*
* @tparam Gcd
* The GCD to return
* @see euclid
*/
template <int Gcd>
struct euclid<Gcd, 0> {
/**
* The GCD of the two original values.
*/
static constexpr int const value{Gcd};
};
【问题讨论】:
-
Doxygen 没有完整的 C++ 解析器。所以它可能会使有效的 C++ 代码出错。当使用解析有效 C++ 代码的 Clang 解析器时,这可能会改变。
-
谢谢,我不知道这个选项存在。我尝试使用 clang 支持重新编译 doxygen 并在配置中激活它(现在,文档构建的第一阶段需要更长的时间),但递归类警告仍然存在。 :(
-
Doxygen 1.7.4 已经提出了同样的问题:stackoverflow.com/questions/5163478/… 我猜你使用的是最新的 Doxygen 1.8.10?可能最好提交一个错误。至少使用 Clang 解析器应该可以弄清楚递归。
-
@usr1234567 我之前发现过,但我认为情况不一样。我有一个自递归的例子,那只是命名冲突。