Can clang be told not to analyze certain files? Can clang be told not to analyze certain files? xcode xcode

Can clang be told not to analyze certain files?


As a last resort, there is a brute force option.

Add this to the beginning of a file:

// Omit from static analysis.#ifndef __clang_analyzer__

Add this to the end:

#endif // not __clang_analyzer__

and clang --analyze won't see the contents of the file.

reference: Controlling Static Analyzer Diagnostics


So, this isn't really an answer, but it worked well enough.

What I ended up doing was building the static library ahead of time, and then building the project using scan-build. Since there was already an up-to-date build of the static library, it wasn't rebuilt and thus wasn't scanned.

I'd still love to have a real answer for this, though.


Finally, in 2018 the option was implemented.

Use --exclude <path> [1] [2] option

--exclude

Do not run static analyzer against files found in this directory (You can specify this option multiple times). Could be useful when project contains 3rd party libraries.