[PATCH] D59336: [clang-tidy] Disable google-runtime-int in Objective-C++ 🔓

Stephane Moore via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 13 15:17:46 PDT 2019

stephanemoore created this revision.
Herald added subscribers: cfe-commits, jdoerfert, xazax.hun.
Herald added a project: clang.

In contrast to Google C++, Objective-C often uses built-in integer types
other than `int`. In fact, the Objective-C runtime itself defines the
types NSInteger¹ and NSUInteger² which are variant types depending on
the target architecture. The Objective-C style guide indicates that
usage of system types with variant sizes is appropriate when handling
values provided by system interfaces³. Objective-C++ is commonly the
result of conversion from Objective-C to Objective-C++ for the purpose
of integrating C++ functionality. The opposite of Objective-C++ being
used to expose Objective-C functionality to C++ is less common,
potentially because Objective-C has a signficantly more uneven presence
on different platforms compared to C++. This generally predisposes
Objective-C++ to commonly being more Objective-C than C++. Forcing
Objective-C++ developers to perform conversions between variant system types
and fixed size integer types depending on target architecture when
Objective-C++ commonly uses variant system types from Objective-C is
likely to lead to more bugs and overhead than benefit. For that reason,
this change proposes to disable google-runtime-int in Objective-C++.

[1] https://developer.apple.com/documentation/objectivec/nsinteger?language=objc
[2] https://developer.apple.com/documentation/objectivec/nsuinteger?language=objc
[3] "Types long, NSInteger, NSUInteger, and CGFloat vary in size between
32- and 64-bit builds. Use of these types is appropriate when handling
values exposed by system interfaces, but they should be avoided for most
other computations."

  rG LLVM Github Monorepo



Index: clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
--- clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
+++ clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
@@ -54,7 +54,9 @@
 void IntegerTypesCheck::registerMatchers(MatchFinder *Finder) {
   // Find all TypeLocs. The relevant Style Guide rule only applies to C++.
-  if (!getLangOpts().CPlusPlus)
+  // This check is also not applied in Objective-C++ sources as Objective-C
+  // often uses built-in integer types other than `int`.
+  if (!getLangOpts().CPlusPlus || getLangOpts().ObjC)
   // Match any integer types, unless they are passed to a printf-based API:

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59336.190518.patch
Type: text/x-patch
Size: 737 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190313/f337d595/attachment.bin>

More information about the cfe-commits mailing list