Clang-tidy ignore system headers in macOS

Hi, I’ve started using clang-tidy on my cmake based project.

Unfortunately, this option isn’t supported on Xcode project generation but only in Makefile.

So when I compiled on the first time, one of the error related to a system include line

#import <Foundation/Foundation.h>

I get the following error :

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSBundle.h:91:143: error: function does not return NSString [clang-diagnostic-error]
- (NSAttributedString *)localizedAttributedStringForKey:(NSString *)key value:(nullable NSString *)value table:(nullable NSString *)tableName NS_FORMAT_ARGUMENT(1) NS_REFINED_FOR_SWIFT API_AVAILABLE(macos(12.0), ios(15.0), watchos(8.0), tvos(15.0));
                                                                                                                                              ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:103:48: note: expanded from macro 'NS_FORMAT_ARGUMENT'
        #define NS_FORMAT_ARGUMENT(A) __attribute__ ((format_arg(A)))
                                                      ^
119827 warnings and 1 error generated.
Error while processing /Users/me/proj/main.mm.
Suppressed 119978 warnings (119822 in non-user code, 5 due to line filter, 151 NOLINT).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Found compiler error(s).
make[2]: *** [CMakeFiles/PASrv.dir/src/main.mm.o] Error 1
make[1]: *** [CMakeFiles/PASrv.dir/all] Error 2

Although it seems correct I’d like to ignore it, but couldn’t do so with // NOLINT since it’s header file, So i’ve read about NOLINTBEGIN and NOLINTEND but it’s supported from llvm 14 and Apple has llvm 12.0.1 and I don’t want to update the entire package because it’s used by Xcode

clang-tidy --version
Homebrew LLVM version 12.0.1
  Optimized build.
  Default target: x86_64-apple-darwin20.6.0
  Host CPU: skylake

any idea how to ignore this system header ?

Have you tried using -header-filter?
You can also use it in .clang-tidy file like:


HeaderFilterRegex:  <your regex>



This functionality has been implemented in D34654.

What you are seeing is a compiler error, not a warning. I don’t think clang-tidy supports ignoring compiler errors (just like you can’t tell a compiler to ignore compiler errors).

For example:

@carlosgalvezp thanks for the feedback, I wasn’t noticed… this is indeed a compilation error. I guess the reason is that when I use clang-tidy, the selected compiler doesn’t supports objective-c/objective-c++.

when compiling the exact same file without clang-tidy, it all works just fine.

Perhaps there is any option to select specific compiler for objective-c/objective-c++ in clang-tidy ?