Index: unittests/clang-tidy/ClangTidyTest.h =================================================================== --- unittests/clang-tidy/ClangTidyTest.h +++ unittests/clang-tidy/ClangTidyTest.h @@ -18,6 +18,7 @@ #include "clang/Tooling/Refactoring.h" #include "clang/Tooling/Tooling.h" #include "llvm/ADT/Optional.h" +#include "llvm/Support/Path.h" #include #include @@ -83,12 +84,19 @@ ClangTidyGlobalOptions(), Options)); ClangTidyDiagnosticConsumer DiagConsumer(Context); - std::vector ArgCXX11(1, "clang-tidy"); - ArgCXX11.push_back("-fsyntax-only"); - ArgCXX11.push_back("-std=c++11"); - ArgCXX11.push_back("-Iinclude"); - ArgCXX11.insert(ArgCXX11.end(), ExtraArgs.begin(), ExtraArgs.end()); - ArgCXX11.push_back(Filename.str()); + std::vector Args(1, "clang-tidy"); + Args.push_back("-fsyntax-only"); + auto extension = llvm::sys::path::extension(Filename.str()); + if (extension == ".m" || extension == ".mm") { + Args.push_back("-fobjc-abi-version=2"); + Args.push_back("-fobjc-arc"); + } + if (extension == ".cc" || extension == ".cpp" || extension == ".mm") { + Args.push_back("-std=c++11"); + } + Args.push_back("-Iinclude"); + Args.insert(Args.end(), ExtraArgs.begin(), ExtraArgs.end()); + Args.push_back(Filename.str()); ast_matchers::MatchFinder Finder; llvm::IntrusiveRefCntPtr InMemoryFileSystem( @@ -99,7 +107,7 @@ SmallVector, 1> Checks; CheckFactory::createChecks(&Context, Checks); tooling::ToolInvocation Invocation( - ArgCXX11, new TestClangTidyAction(Checks, Finder, Context), Files.get()); + Args, new TestClangTidyAction(Checks, Finder, Context), Files.get()); InMemoryFileSystem->addFile(Filename, 0, llvm::MemoryBuffer::getMemBuffer(Code)); for (const auto &FileContent : PathsToContent) {