Doxygen:使用 "UNUSED" 宏处理未使用的函数参数

Doxygen : handling unused function parameters with "UNUSED" macro

简短版

为了防止编译器发出有关未使用变量的警告,我将宏 UNUSED 定义为:

UNUSED(x)=x __attribute__((__unused__))

这个宏被用于一些函数的原型,例如:

void ext(int foo, int UNUSED( bar ) )

然而,doxygen 对此并不满意,returns 一些警告:

/tmp/sandbox/main.cpp:13: warning: argument 'bar' of command @param is not found in the argument list of Dummy::ext(int foo, intUNUSEDbar)
/tmp/sandbox/main.cpp:13: warning: The following parameters of Dummy::ext(int foo, intUNUSEDbar) are not documented:
  parameter 'UNUSED'

我应该如何告诉 doxygen 忽略 UNUSED 宏?

长版

我的代码如下所示:

#include <iostream>

class Dummy
//! Dummy class
{
public :

    //!Dummy function
    /**
     * \param foo First  variable
     * \param bar Second variable
    */
    void ext(int foo, int UNUSED( bar ) )
    {
        std::cout << "foo = " << foo << std::endl;
    }
};


//!Main function
int main(void)
{
    Dummy MyDummy;
    MyDummy.ext(1, 2);
    return 0;
}

我通过调用编译它:

g++ -D 'UNUSED(x)=x __attribute__((__unused__))' main.cpp

要生成名为 Doxyfile 的默认 doxygen 配置文件,我输入:

doxygen -g

最后,为了生成我输入的文档:

doxygen Doxyfile

后一个命令输出以下警告:

/tmp/sandbox/main.cpp:13: warning: argument 'bar' of command @param is not found in the argument list of Dummy::ext(int foo, intUNUSEDbar)
/tmp/sandbox/main.cpp:13: warning: The following parameters of Dummy::ext(int foo, intUNUSEDbar) are not documented:
  parameter 'UNUSED'

按照 doxygen documentation 的说明,修改 Doxyfile,使其具有以下参数:

#Doxygen will run its own preprocessor before parsing the file
ENABLE_PREPROCESSING   = YES

#The Doxygen preprocessor will not only define the macros (default
#behaviour) but also expand them
MACRO_EXPANSION        = YES

#The Doxygen preprocessor will only expand the macros that are listed in
#the PREDEFINED setting. Any other macro will merely be defined, and not
#expanded.
EXPAND_ONLY_PREDEF     = YES

#The Doxygen preprocessor will replace any occurrence of the UNUSED
#macro by its argument
PREDEFINED             = UNUSED(x)=x

进行这些更改后,调用 doxygen Doxyfile 不再引发警告。