Ignore all warnings in a specific file using LLVM / Clang

My iOS project has several files with some warnings, and I want to ignore these warnings. I do not want to turn off warnings in the entire project (I know how to do this), only some specific files. So, is there a way to completely ignore all warnings from a specific file?

I am using LLVM 3.0 and Clang on Xcode 4.2.

+58
compiler-warnings xcode clang
Oct 26 '11 at 0:26
source share
4 answers

if you just use clang, then you should use the pragma syntax for the sources you support (provided that it is not possible to remove the warning by changing the program accordingly).

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 that you cannot modify and do not support, you should specify a warning to disable the file, and not all. to disable everything, you can add an argument to the -w file. sources, and some warnings (or do not apply) apply with different build settings. clang messages can tell you which flag matches the warning generated.

To use Xcode to change file assembly flags:

  • select target
  • select build phase
  • find the file to change the arguments in the Compilation Sources phase
  • double click on the flag compiler cell to change
+58
Oct 26 2018-11-11T00:
source share

I inherited a project that contained a lot of code 320, and this code base gave me some warnings and static errors of the analyzer that I had no interest in fixing it, since I will remove this code from the project in the near future.

You can turn off static analyzer warnings for a specific file by turning on the following compiler flag:

 -Xanalyzer -analyzer-disable-all-checks 

You can combine this with -w to disable warnings for this file. This allowed me to move forward with the new development, while I did not have to pester the 30 warnings created by this code base.

Using the instructions above: To use Xcode to change file assembly flags:

  • select target
  • select build phase
  • find the file to change the arguments in the Compilation Sources phase
  • double click on the flag compiler cell to change
  • add "-w -Xanalyzer -analyzer-disable-all-checks" to suppress clang warnings and warnings
+87
Nov 10 '11 at
source share

With justin answer, here's how you do it

1. Find the name of the warning.

In my case, its conversion

enter image description here

2. Adding compiler flag assembly phases for each file

Use the filter to find the file name in compilation sources, enter -Wno-[error name] for example. -Wno-conversion

enter image description here

+14
03 Feb '15 at 13:21
source share

You can select a specific target → Build settings, search for the prohibition of all warnings and set the value to “YES”. This will disable alerts for this purpose. This can be useful if you use some kind of code like JSONKit with cocoapods and you don't want to see the compiler cry about warnings :)

+2
Nov 29 '13 at 0:47
source share



All Articles