代码之家  ›  专栏  ›  技术社区  ›  Malvineous

如何禁用叮当警告“无案例匹配恒定开关条件”

  •  1
  • Malvineous  · 技术社区  · 7 年前

    我正在处理一个使用另一个项目的代码的项目,而另一个代码在编译期间给了我一大堆警告。我不想更改这些代码(我的项目只是他们代码的一个薄薄包装,我希望能够在不进行任何修补的情况下获取更新),因此我想禁用这些警告,以便我可以只关注自己的代码。

    我收到的错误是:

    warning: no case matching constant switch condition '2'
    

    我有 looked in the manual 并尝试 -Wno-switch , -Wno-switch-bool -Wno-switch-enum

    使用Google,我无法找到任何与错误文本匹配的命令行选项。

    使用GitHub,我能够找到 runs a test for this warning 但我没法把它映射回 -W 选项来禁用它。

    我错过了什么?

    下面是一些重现错误的代码:

    enum En { A, B, C };
    template <En how> void foo() {
        int x = 0, y = 5;
    
        switch (how) {
            case A: x *= y; break;
            case B: x += y; break;
        }
    }
    
    template void foo<C>();
    
    int main(void)
    {
        return 0;
    }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Mike Kinghan Luchian Grigore    7 年前

    -Wno-<what> 可专门抑制此警告的标志。

    warning: no case matching constant switch condition '2' [-W<what>]
    

    全部的 -Wno-everything , 我当然不会建议这样做。