Index: clang-tidy/google/AvoidCStyleCastsCheck.cpp =================================================================== --- clang-tidy/google/AvoidCStyleCastsCheck.cpp +++ clang-tidy/google/AvoidCStyleCastsCheck.cpp @@ -110,6 +110,10 @@ // compiled as C++. if (getCurrentMainFile().endswith(".c")) return; + // Ignore casts between Objective-C types. + if (SourceType->isObjCObjectPointerType() || + DestType->isObjCObjectPointerType()) + return; SourceManager &SM = *Result.SourceManager; Index: test/clang-tidy/google-readability-casting.mm =================================================================== --- /dev/null +++ test/clang-tidy/google-readability-casting.mm @@ -0,0 +1,42 @@ +// RUN: clang-tidy %s -checks=-*,google-readability-casting -- \ +// RUN: -xobjective-c++ -fobjc-abi-version=2 -fobjc-arc | count 0 + +// Note: this test expects no diagnostics, but FileCheck cannot handle that, +// hence the use of | count 0. + +#define nil 0 + +@interface Foo +@end + +@protocol Proto +@end + +@interface Bar : Foo +@end + +@interface Baz : Foo +@end + +void foo() { + id nilObj = nil; + Foo *foo = (Foo *)nilObj; + Bar *bar = (Bar *)nilObj; + id ego = (id)foo; + foo = (Foo *)bar; + foo = (id)bar; + id nilProto = (id)bar; + ego = (id)nilProto; + bar = (Bar *)nilProto; + Foo *fooProto = (Foo *)bar; + Baz *baz = (Baz *)bar; + Class klass = (Class)nilObj; + ego = (id)klass; + void *voidStar = nullptr; + foo = (__bridge Foo *)voidStar; + nilProto = (__bridge id)voidStar; + klass = (__bridge Class)voidStar; + voidStar = (__bridge void *)foo; + voidStar = (__bridge void *)nilProto; + voidStar = (__bridge void *)klass; +}