Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct way to suppress Xcode's unused function warning for inline functions in library header

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.

like image 584
Danra Avatar asked Jun 29 '16 13:06

Danra


2 Answers

Changing the function to static inline instead of just static resolves the issue.

like image 92
Danra Avatar answered Sep 29 '22 20:09

Danra


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.

like image 20
N. Shead Avatar answered Sep 29 '22 22:09

N. Shead