禁用"未使用的功能"特定功能名称

时间:2015-04-28 10:03:05

标签: c++ gcc gcc-warning

我用&#34编译项目;将警告视为错误"。

问题是,我需要从这里增加类​​型列表:

https://stackoverflow.com/a/24092000/508023

GCC理所当然地抱怨说既没有定义也没有使用一组声明的静态函数。我不想完全禁用此诊断。相反,我想仅为具有特定名称的函数禁用它。有可能吗?也许有些属性?还是编译选项?

澄清:我不需要为指定的文件禁用警告。我需要为特定功能禁用它。

编辑:我能够通过使用基于ADL的技巧解决我的问题。所以问题不再是实际的。

2 个答案:

答案 0 :(得分:2)

最好使用__attribute__((unused)) GCC扩展程序,例如the code below

namespace {
    void f() __attribute__((unused));
    void g();

    void f() {}
    void g() {}
}

int main() {/*f(); g();*/ return 0;}

答案 1 :(得分:0)

在C ++ 17中,您可以使用[[maybe_unused]]声明函数:

[[maybe_unused]] void foo (int, int);

来源:https://stackoverflow.com/a/41551608/81614