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

时间:2016-03-30 09:50:19

标签: doxygen unused-variables

短版

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

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

然后在一些函数的原型中使用该宏,例如:

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

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

/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'

1 个答案:

答案 0 :(得分:2)

按照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不再提出警告。