What is the correct way to suppress Xcode's unused function warning for functions in a library header?
For example, I have the following function defined in MathUtils.h:
namespace MathUtils {
static std::complex<double> cis(double x) {
return std::complex<double>(cos(x), sin(x));
}
...
}
Source files which include this header, but don't use this specific function, trigger the warning.
I could add a warning pragma around the function to disable the warning, but that doesn't seem like the right way - this seems like a general issue.
Changing the function to static inline
instead of just static
resolves the issue.
If you specify the location of the file with -isystem
rather than -I
, clang will silently ignore all warnings in the header file. For more information, see http://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-in-system-headers.
To do this with XCode, as far as I know you have to add the appropriate compiler flag to the 'Other C++ Flags' section of the Build Settings.
Also, you are only getting warnings because you defined the function with static
- that means that the function is defined separately in each translation unit you include the header in, and is not visible to any other units. You can get rid of the errors just by removing the static
keyword.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With