1
votes

In Xcode, at the project level I have the following setting; Xcode setting to suppress deprecated function warning

This adds -Wno-deprecated-declarations to compilation which I can verify from Report Navigator. Also when I try to use a deprecated function no warning is raised.

I want to suppress this warning within a single file so I used #pragma as follows;

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wno-deprecated-declarations"

deprecated_function_call();

#pragma clang diagnostic pop

This code gives the following compilation error; error: unknown warning group '-Wno-deprecated-declarations', ignored [-Werror,-Wunknown-pragmas]

pragma clang diagnostic ignored "-Wno-deprecated-declarations"

How is it possible that compiler can use this warning flag and I cannot in my pragmas.

My clang version; Apple LLVM version 8.0.0 (clang-800.0.36.1)

1

1 Answers

2
votes

Try:

#pragma clang diagnostic ignored "-Wdeprecated-declarations"

Instead of:

#pragma clang diagnostic ignored "-Wno-deprecated-declarations"

I just had a similar issue with "-Wno-sign-compare", which was fixed by using "-Wsign-compare" (dropped the "no-" part) instead.

Based on this behavior I expect that, in your case, "deprecated-declarations" is the actual name of the warning group, and the "no-" prefix is added when used as a compiler option to indicated that warnings in this group should be ignored. The pragma already contains the "ignored" keyword, possibly explaining why the same syntax is not used in pragmas.