问题
I know that #pragma clang diagnostics can be used for ignoring some warnings generated by clang. But I don't know how to use this correctly.
For example, for an unused variable warning we can avoid warning by
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
int number;
#pragma clang diagnostic pop
But I don't know how to get correct parameter for #pragma clang diagnostic ignored ("-Wunused-variable" here)
Is there any way to fing this kind of warning name for specific warnings with xcode?
回答1:
Right click on the issue in the issue navigator and select "Reveal in Log". The error message will specify the warning.
回答2:
You can look up the warning command line parameter if you know the message: Diagnostic flags in Clang
回答3:
Ok, then this is what I understood
Clang
is the C/Objective C Front end Layer for compiler.
and Clang take the responsibility of showing Warning and Error message that we see in Xcode.
So when you enable the option of treat your warning as Error in Xcode, In some cases you need a tool to work around about the Clang to allow some warnings..
and here Clang Diagnostics
play that role..
and the mechanism for that is like Graph Matrix, which is happened in Stack way..Push and Pop..
so when you have something like this..
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcovered-switch-default"
// Code.........
#pragma clang diagnostic pop
you are preventing Clang to show warning messages on that area, so it something like SafeArea..
and you can find more Clang Warning that you can avoid here.. http://fuckingclangwarnings.com
来源:https://stackoverflow.com/questions/20078941/how-to-use-pragma-clang-diagnostics