This is an archive of the discontinued LLVM Phabricator instance.

Allow IncludeSorter to use #import for Objective-C files
AbandonedPublic

Authored by compositeprimes on Dec 10 2018, 8:03 PM.

Details

Summary

The change infers whether a source file is Objective-C using LangOpts, and if it detects Objective-C, it uses "#import" instead of "#include" for all inserted imports.

Diff Detail

Event Timeline

Please add a unittest for it, you can add it in unittests/clang-tidy/IncludeInserterTest.cpp.

clang-tidy/utils/IncludeSorter.cpp
116

What about the ObjC++? The current behavior is always using #import, google objc style guide says #import Objective-C and Objective-C++ headers, and #include C/C++ headers., I don't think we have a way to do it smartly.

Maybe a conservative way is to use #import for ObjC only?

benhamilton added inline comments.Dec 13 2018, 10:35 AM
clang-tidy/utils/IncludeSorter.cpp
116

Yeah, came here to say this. Let's enable #import for ObjC but disable for C++ (which will include ObjC++).

benhamilton requested changes to this revision.Jan 30 2019, 5:53 AM
This revision now requires changes to proceed.Jan 30 2019, 5:53 AM
compositeprimes abandoned this revision.Feb 27 2020, 11:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 27 2020, 11:16 AM
Herald added a subscriber: mgehre. · View Herald Transcript