7

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.

Danra
  • 9,546
  • 5
  • 59
  • 117
  • What are compiler options when the warning is triggered? What are the versions of xcode and clang? – osgx Jul 01 '16 at 17:07
  • Both Xcode 7/8. Relevant warning is Unused Functions. – Danra Jul 01 '16 at 17:45
  • Danra, full compiler command with all command line options? (check full build log - "Expand All Transcripts" - http://stackoverflow.com/questions/19014359/how-do-i-view-the-full-build-log-on-xcode5 - there should be command with clang) – osgx Jul 01 '16 at 19:25
  • Here it is in most of its glory (some includes, defines and paths redacted) http://pastebin.com/6U5eXUGJ – Danra Jul 01 '16 at 20:27

2 Answers2

8

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

Danra
  • 9,546
  • 5
  • 59
  • 117
4

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.

N. Shead
  • 3,828
  • 1
  • 16
  • 22
  • Removing the static creates linker errors in case the header is included in more than one module. – Danra Jul 03 '16 at 10:14