【问题标题】:Doxygen : handling unused function parameters with "UNUSED" macroDoxygen:使用“UNUSED”宏处理未使用的函数参数
【发布时间】:2016-03-30 09:50:18
【问题描述】:

短版

为了防止编译器对未使用的变量发出警告,我将宏 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'

【问题讨论】:

  • 您看过手册的预处理器部分吗?也许 UNUSED(x) 的 doxyfile 中的 PREDEFINED 可能会有所帮助
  • 我刚刚看了doxygen's doc on preprocessing:确实,那里都解释了!感谢您的提示!

标签: doxygen unused-variables


【解决方案1】:

按照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 不再引发警告。

【讨论】:

    猜你喜欢
    • 2014-06-07
    • 2016-03-07
    • 2011-05-31
    • 2021-05-07
    • 2020-11-22
    • 2019-02-18
    • 1970-01-01
    • 2017-01-12
    相关资源
    最近更新 更多