我可以在函数头中包含cppcheck抑制吗? [英] Can I include cppcheck suppression within a function header?

查看:118
本文介绍了我可以在函数头中包含cppcheck抑制吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了一个内联注释抑制一个函数的cppcheck未使用的函数警告,但我想包括这个在函数头,以便Doxygen可以记录所有未使用的函数(我正在实现一个API,所以我有许多功能,不会在我的源中使用)。我想不要抑制所有未使用的函数错误,而是基于每个函数。

I have added an inline comment to suppress a cppcheck unusedFunction warning for a function, but I would like to include this within the function header so that Doxygen can document all of the unused functions (I am implementing an API, so I have many functions that will not be used in my source). I would prefer not to suppress all unusedFunction errors, but rather on a per-function basis.

我想这样做:

/**
 * API function description
 * 
 * @param p1 function pointer to the ...
 * @return 0 if successful, -1 otherwise.
 * // cppcheck-suppress unusedFunction
 */
int CreateTask(Task_FuncPtr p1)
{    
    return doSomething();
}

但是当我这样做时,cppcheck不看到内联抑制。如果我把它移到标题外,但只是在函数声明之前,那么抑制工作。 cppcheck文档似乎意味着抑制需要直接在生成行的错误之前。

But when I do this, cppcheck does not "see" the inline suppression. If I move it outside the header, but just before the function declaration then the suppression works. The cppcheck documentation seems to imply that the suppression needs to be directly before the line generating then error.

有没有成功?

推荐答案

cppcheck 来源(文件 preprocessor.cpp 函数 RemoveComments()),似乎你不能这样做。

Taking a look at cppcheck sources (file preprocessor.cpp function RemoveComments()), it seems that you cannot do it.

标识注释的代码是:

if (str.compare(i, 2, "//") == 0) { /* ... */ }

>

and

else if (str.compare(i, 2, "/*") == 0) { /* ... */ }

当发现注释时,管理警告抑制的代码是:

When a comment is found, the code that manages warning suppression is:

if (_settings && _settings->_inlineSuppressions) {
    std::istringstream iss(comment);
    std::string word;
    iss >> word;
    if (word == "cppcheck-suppress") {
        iss >> word;
        if (iss)
            suppressionIDs.push_back(word);
    }
}

因此 cppcheck 将跳过空格并在 // / * 后立即检查第一个令牌。

So cppcheck will skip spaces and check the first token immediately after // or /*.

不幸的是Doxygen的特殊注释块以 / ** /// / *! //!,第三个字符会阻止正确匹配。

Unfortunately Doxygen's special comment blocks start with /**, ///, /*! or //! and the third character prevents the "correct match".

更改:

if (word == "cppcheck-suppress") { /* ... */ }

into:

if (contains(word, "cppcheck-suppress")) { /* ... */ }
// or if (ends_with(word, "cppcheck-suppress"))

应该允许您想要的:

/**
 * API function description
 *
 * @param p1 function pointer to the ...
 * @return 0 if successful, -1 otherwise.
 */
/** cppcheck-suppress unusedFunction */

/ p>

or

/// API function description
///
/// @param p1 function pointer to the ...
/// @return 0 if successful, -1 otherwise.
///
/// cppcheck-suppress unusedFunction

http://trac.cppcheck.net/ 上打开支票

这篇关于我可以在函数头中包含cppcheck抑制吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆