[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 3 13:12:12 PST 2024


================
@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector<StringRef> CppNonKeywordTypes = {
+    "byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+    "size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",
----------------
zygoloid wrote:

On codesearch.isocpp.org, `(intptr_t)` is more common than `(int8_t)` and `(int16_t)`, and similar to `(int32_t)`. But why should this general function that's used in various places in clang-format care about how often the type is cast with a C-style cast? That doesn't make sense to me.

I find it extremely unlikely that anyone would use `intN_t` as anything other than a type; I think your concerns about regressions are unfounded. In contrast, there are 518 hits for `(intptr_t)&` in isocpp codesearch, which seems pretty logical to me because casts to `(intptr_t)` will be casts from pointers.

https://github.com/llvm/llvm-project/pull/83709


More information about the cfe-commits mailing list