Ignore all warnings in a specific file using LLVM/Clang

前端 未结 4 2120
逝去的感伤
逝去的感伤 2020-12-02 05:41

There are some files in my iOS project that have some warnings, and I want to ignore those warnings. I don\'t want to disable warnings in the entire project (know how to do

4条回答
  •  生来不讨喜
    2020-12-02 06:12

    if you're just using clang, then you should use the pragma syntax for sources you maintain (assuming it is impossible to remove the warning by altering the program appropriately).

    here is the syntax:

    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wmultichar"
    
    char b = 'df'; // no warning.
    
    #pragma clang diagnostic pop
    

    if these are programs you cannot change and don't maintain, you should specify the warning(s) to disable for the file, rather than all. to disable all, you can add the per file argument -w. sources change, and some warnings do (or do not) apply with different build settings. clang's messages can tell you what flag equates to the generated warning.

    To use Xcode to alter a file's build flags:

    • select the target
    • select the build phase
    • locate the file to modify the arguments in the "Compile Sources" phase
    • double click its "Compiler Flags" cell to edit

提交回复
热议问题