Disable a specific warning in xcode's live-checking only - xcode

XCode's live issue tracking is great, most of the time. But there are a few warnings it complains about that get annoying when I'm still in the middle of writing. For instance, unused variables:
I know it's unused, I just finished that line and haven't gotten to the code that uses it yet.
I am fairly anal about compiling without warnings (on -Wall -Wextra -pedantic, minus a couple particular ones), so seeing them when I haven't yet had the chance to address them is a bit irritating. However, I do like most of the live-build warnings and once I actually build, I do want to see these.
So, is there any way to disable certain warnings on the live-issue checking only, keeping them on actual builds? I would be willing to use release settings for live-issue and debug for manual builds if that is possible.
A potential workaround I would also accept is delaying the live checking to only run after 10-15 seconds of inactivity.

Usually i used to do the following to avoid the "unused variable".
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
NSArray *ary = [[NSArray alloc] init];
//your code area
#pragma clang diagnostic pop
So the real time waring for "unused variable" is off on the section. and when i need to enable this i just commented out the "#pragma".
Reference

using a #pragma to disable the warning will affect live-preview / compilation time... I dont think there is such a way in xcode. :(

Related

Is there any way to disable all warnings with a pragma in clang or gcc?

GCC and clang let you compile with -w to disable all warnings, but I can't see a #pragma equivalent of it. I can see only pragma support for disabling individual files.
I need this because I have code that I want to compile with high warning levels but which necessarily compiles third party code which generates arbitrary warnings.
You can kind of do it with GCC, almost, using #pragma GCC diagnostic ignored, but unluckily not very well, see here.
The problem is that you cannot just "disable all", you have to disable each single one. Plus, for some warnings it doesn't work (and the docs don't tell you which ones...).
My guess is that this somewhat preliminary and will (hopefully) be improved in the next version.

Can I have different warning levels for different folders in Xcode?

I compile my Xcode projects with very high warnings settings. Sometimes, I have to use third-party frameworks that are distributed as source (rather than as a framework). These frameworks often throw a lot of warnings.
Is there a way to turn off warnings for these folders? I want the stricter level for my own code, but don't care if third-party code violates my warnings level.
Basically, I don't want to see 67 warnings every time I build.
You're looking for this:
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
Flags can be found here: http://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Warning-Options.html
Just replace the -W... with whatever you want to ignore.

How do I disable Xcode static analysis (Clang) messages?

I'd like my Xcode project to go through a Build And Analyze step without generating any errors, warnings, or static analysis messages. A problem with this is that my project includes libraries that generate (possibly innocuous) warnings and static analysis messages.
I can't find a way to disable specific Clang warnings so that "my" code builds with zero issues. Is this possible?
I wasn't able to find any way to do this, and filed a bug against Clang. The team seems to want to add this functionality, but it's not there yet.
The bug is: http://llvm.org/bugs/show_bug.cgi?id=7296
Also, one can use a __clang_analyzer__ macro to ifdef out any code that one doesn't want Clang to process.
The Build and Analyze step is clang - thats the "analyze" part. It wouldn't make sense to analyze your code and not have clang tell you about issues it find. That's like going to a car wash and telling them not to touch the car.
From talking to the guy that wrote clang at WWDC, it is extremely unlikely that anything it identifies as an issue is actually not. If you think you have some examples of code that works fine but clang complains, please file a bugreport with example code so Apple can fix that.
You can disable some compiler warnings through the use of flags, but not all of them are an option.

-isystem for MS Visual Studio C++ Compiler

I usually like to have a lot of warnings enabled when programming. However, some libraries contains code that easily causes warnings (.., python, Qt, ..). When compiling with gcc I can just use -isystem instead of -I to silence that. How can I do the same with the MS compiler? I know of the warning #pragma, but I would like a solution that does not involve compiler specific code all over the place. I also know that I can turn off specific warnings, but that is not what I want either.
BTW: isystem should be a tag of this question, but I was not allowed to do that..
SUMMARY: I want to see all warnings from my code, and no warnings from external code.
As of 2017-08-17 this still seems impossible.
I added a feature request here:
https://developercommunity.visualstudio.com/content/problem/96411/impossible-to-ignore-warnings-from-system-librarie.html
Update 2018:
The issue is now closed as fixed and is available in the standard MS VS installation [source].
A blog post from the MS team goes through the new features [here].
The solution from MS is flexible. You can not only differentiate using paths like you do with --isystem, but for example also by whether you use #include "" or #include <>. The blog post is worth a read to see all the various customization points.
This now exists under /experimental:external /external:I system_include_path /external:W0. See https://blogs.msdn.microsoft.com/vcblog/2017/12/13/broken-warnings-theory/ for many more details.
No clue why MS never picked this up.
We can only try voting on https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/14717934-add-a-cl-exe-option-for-system-headers-like-gcc-s
No, MSVC doesn't have an -isystem equivalent.
look at the output output from cl /? :
/wd disable warning n
/we treat warning n as an error
/wo issue warning n once
/w set warning level 1-4 for n
Note that this disables the warnings for your entire project; I remember when using Qt I'd rather change it's main header with the #pragma warning disable and enable at the end again so I could still see all warnings for my own source.
Edit the author edited his question, updated answer: there is no way to get your code with warnings and Qt code without warnings using compiler flags: how are you going to tell the compiler what is 'your' code?
Note that the above flags can be applied at file level as well, so this would allow you to disable the warnings for only those files in which you include Qt headers, but that still means you cannot see them for your own code in that files.
So I stay with the answer above; it is not quite pretty, but I'm pretty sure it's the only way: use #pragma at the beginning and the end of the Qt header(s). Either change the Qt headers (even more ugly), or choose a less invasive way like this:
//your source/header file
#include "shutuppqt.h"
#include <QString>
#include "enableallwarnings.h"
example "shutuppqt.h"
#ifdef MSVC
#pragma warning ( disable : 4222 ) //or whatever warning Qt emits
#else
//....
#endif
example "enableallwarnings.h"
#ifdef MSVC
#pragma warning ( enable : 4222 ) //or default instead of enable
#else
//....
#endif

Change some GCC warnings into errors

In my makefile I specify -Werror=uninitialized, but no errors occur.
I changed it to -Wuninitialized, and I see my warning. -Wno-uninitialized makes it go away as expected, but why isn’t -Werror=uninitialized working?
Also it was suggested in code I write
#pragma GCC diagnostic error "-Wuninitialized"
But that does not work either. Why?
I have another question, but unfortunately none of the suggestions are working for me.
You should use -Werror. This option doesn't have any parameters (it is an on/off switch).
But it is good practice to remove all warnings, so -Werror enforces this good practice.

Resources