我可以在函数头中包含cppcheck抑制吗
Can I include cppcheck suppression within a function header?
我添加了一个内联注释来抑制函数的cppcheck unusedFunction警告,但我希望将其包含在函数头中,以便Doxygen可以记录所有未使用的函数(我正在实现API,因此我有许多函数将不会在我的源代码中使用)。我不希望抑制所有未使用的函数错误,而是基于每个函数。
我想做这样的事情:
/**
* 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文档似乎暗示了抑制需要直接在生成then错误的行之前。
有人成功了吗?
查看cppcheck
源(文件preprocessor.cpp
函数RemoveComments()
),似乎无法做到这一点。
识别注释的代码是:
if (str.compare(i, 2, "//") == 0) { /* ... */ }
和
else if (str.compare(i, 2, "/*") == 0) { /* ... */ }
当发现注释时,管理警告抑制的代码是:
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
将跳过空格并立即检查//
或/*
之后的第一个令牌。
不幸的是,Doxygen的特殊注释块以/**
、///
、/*!
或//!
开头,第三个字符阻止了"正确匹配"。
更改:
if (word == "cppcheck-suppress") { /* ... */ }
进入:
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 */
或
/// API function description
///
/// @param p1 function pointer to the ...
/// @return 0 if successful, -1 otherwise.
///
/// cppcheck-suppress unusedFunction
你也许可以在http://trac.cppcheck.net/
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 从包含m行的文件中提取n行,必要时(惰性地)重复该文件
- 编译包含字符串的代码时遇到问题
- c++库的公共头文件中应该包含什么
- Cppcheck生成xml转储文件
- 将包含C样式数组的对象初始化为成员变量(C++)
- 是否需要删除包含对象的"pair"?
- 函数何时会在c++中包含stack_Unwind_Resume调用
- cppcheck在const std::string[]上引发警告
- 如何将包含epoch时间的十六进制字符串转换为time_t
- 使用mongocxx驱动程序时包含头文件问题
- 如何在h文件中包含.o对象文件
- 在混合代码库中将C转换为C++时出现许多包含错误
- VS2017,C++包含目录与附加包含目录,子文件夹包含失败-但为什么
- cmath抛出错误C2062、C2059、C2143和C2447.cmath包含在矢量文件中
- 为什么您需要C++头文件的包含保护
- 无法在UE4中包含BP类到CPP类
- 如何使用cppcheck处理半相对包含路径
- CPPcheck 找不到包含文件
- 我可以在函数头中包含cppcheck抑制吗