【问题标题】:Can I include cppcheck suppression within a function header?我可以在函数头中包含 cppcheck 抑制吗?
【发布时间】:2015-06-29 13:41:58
【问题描述】:

我添加了一个内联注释来抑制函数的 cppcheck usedFunction 警告,但我想将它包含在函数头中,以便 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 documentation 似乎暗示抑制需要直接在生成然后错误的行之前。

有没有成功的?

【问题讨论】:

    标签: c++ c header doxygen cppcheck


    【解决方案1】:

    看看cppcheck源(文件preprocessor.cpp函数RemoveComments()),好像做不到。

    识别cmets的代码是:

    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/ 上开票

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-17
      • 1970-01-01
      • 2014-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多