How to suppress "Availability does not match previous declaration" warning - ios

I have to use some private functions, like:
SCDynamicStoreRef
SCDynamicStoreCreate (
CFAllocatorRef allocator,
CFStringRef name,
SCDynamicStoreCallBack callout,
SCDynamicStoreContext *context
) __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA);
By default they are not allowed for iphone, so I've changed declaration of them in my .m file. But now it shows "Availability does not match previous declaration" warning. How to suppress this warning?

With the usual disclaimer that using private APIs might cause your app to be rejected:
You can suppress the warning with
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wavailability"
…
#pragma clang diagnostic pop
It might also cause crashes or other failures if that function is present in the iOS
frameworks, but with different parameters.

Related

How to disable the warning for pragma message in Clang?

#pragma message is implemented in Clang as warning.
Is there any way to disable the warning only for this pragma, so it will be have like MS Visual Studio, or some other way to give informational messages from code ?
(I need an answer as an end user with a given Clang, I cannot re-compile the Clang itself on this project)
I realize this post is a year old and the OP probably already found his answer but since I was looking for the answer myself I thought I may as well include the info here.
From the Clang user's manual:
https://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas
The pragma may control any warning that can be used from the command line. Warnings may be set to ignored, warning, error, or fatal.
Attempting to set the class to something other than the above:
#pragma clang diagnostic push
#pragma clang diagnostic note "-W#pragma-messages"
#pragma message "HELLO!"
#pragma clang diagnostic pop
int main(int argc, char **argv)
{
}
Results in a warning showing the same options:
/tmp/test.cc:3:26: warning: pragma diagnostic expected 'error', 'warning', 'ignored', 'fatal', 'push', or 'pop' [-Wunknown-pragmas]
#pragma clang diagnostic note "-W#pragma-messages"
^
/tmp/test.cc:4:9: warning: HELLO! [-W#pragma-messages]
#pragma message "HELLO!"
^
2 warnings generated.
So it appears that as of Clang 5.0 there is no way to treat the message as informational instead of as a warning.

Warning equivalent of #pragma poison

I use the crash function for testing Crashlytics integrations, but I obviously never want to ship that code in an app.
It's possible to poison identifiers so that any current or future use causes an error:
#pragma GCC poison crash
Is there an equivalent #pragma directive that emits a warning when an identifier is used? I want to be able to build the codebase while retaining a visible indicator that attention is required.
This should work, now that _Pragma is available. Instead of using #pragma GCC poison, you can just #define the identifier crash in a way which will generate a warning using #pragma GCC warning:
#define DO_PRAGMA(x) _Pragma(#x)
#define WARN(x) DO_PRAGMA(GCC warning #x)
#define crash WARN("crash" used) crash
The first two macros just make it less work to escape quotation marks. Note that crash expands to itself (as well as the _Pragma), which works because the C preprocessor doesn't expand a token inside of its own expansion.
If you change warning to error, you'll get an error instead. You could easily arrange to change all of those by using some more macros, or you could just use -Werror
You could use #warning
Usage would be as follows:
#warning This is a custom message

Ignore CGFloat type warning

I've got a function with such part of code:
if (CGFLOAT_IS_DOUBLE) {
return fabs(x / y);
} else {
return fabsf(x / y);
}
However with new Xcode I'm obtaining a warning here:
Absolute value function 'fabsf' given an argument of type 'double' but
has parameter of type 'float' which may cause truncation of value
The warning wasn't visible in Xcode 6, but in Xcode 7 Beta it is.
With such wrapping, I'm moreover sure that the values are float type. Now the question is how to suppress the warning?
I've tried with many Clang flags, ended on most general:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wall"
// above code
#pragma clang diagnostic pop
But it doesn't help (odd?). "-W" also doesn't help. Any tip..?
I don't want to cast, create extra float variables nor anything similar. I just want to silence the warning.

Return statement will never be executed warning

I've recently come across with double return statement (one of them was added by mistake) in our project and wondering why compiler doesn't show a warning for that?!
Ok, I added -Wunreachable-code to other warning flags, but still no luck.
Got warning - with a code to execute after return statement:
Didn't get warning but still second return statement will never be executed.
Even if I add something like this, still no warning
Is there extra warning flag for that, or compiler isn't smart enough?
Good catch!
-Wunreachable-code does not report a warning and there is no other warning flag which would do.
Not even the Static Analyzer catches this mistake!
(Tested with XCode 6.1 GM 2)
Wrap your code in pragma flags that will suppress that warning between the push and pop
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunreachable-code"
//Your code goes here
#pragma GCC diagnostic pop
Use -Wno-unreachable-code for your file in Build Phases.
Try this...
-(NSString*) makeSomeStringForMe {
NSString *someString = #"some string";
return someString;
}

Is there a Clang diagnostic that is only a note?

Clang has several kinds of diagnostics, of which the three main kinds are errors, warnings, and notes.
Notes usually accompany certain warnings and errors, such as duplicate definitions:
error: conflicting types for 'square'
static double square(double x) {
^
note: previous declaration is here
static int square(int x);
^
What I want to know is, does Clang have any diagnostics—especially for Objective-C or C, but I'll settle for C++ if I have to—that consist of only a note, with no associated error or warning?
http://clang.llvm.org/docs/InternalsManual.html#the-diagnostic-kinds-td-files says:
These severities are mapped into a smaller set (the Diagnostic::Level
enum, {Ignored, Note, Warning, Error, Fatal}) of output levels by the
diagnostics subsystem based on various configuration options. Clang
internally supports a fully fine grained mapping mechanism that allows
you to map almost any diagnostic to the output level that you want.
The only diagnostics that cannot be mapped are NOTEs, which always
follow the severity of the previously emitted diagnostic and ERRORs,
which can only be mapped to Fatal (it is not possible to turn an error
into a warning, for example).
So unfortunately no; you can't do that without hacking Clang itself. Notes are intended only for linking to other diagnostics. I'd file a bug with the LLVM tracker; this would definitely be useful functionality.

Resources