[PATCH] D81455: [clang][NFC] Generate the {Type,ArrayType,UnaryExprOrType,Expression}Traits enumerations from TokenKinds.def...

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 10 12:47:13 PDT 2020


aaron.ballman added inline comments.


================
Comment at: clang/lib/Basic/ExpressionTraits.cpp:29-34
+  assert(T <= ET_Last && "invalid enum value!");
+  return ExpressionTraitNames[T];
+}
+
+const char *clang::getTraitSpelling(ExpressionTrait T) {
+  assert(T <= ET_Last && "invalid enum value!");
----------------
Isn't `ET_Last` -1?


================
Comment at: clang/lib/Basic/TypeTraits.cpp:64
+const char *clang::getTraitName(ArrayTypeTrait T) {
+  assert(T <= ATT_Last && "invalid enum value!");
+  return ArrayTypeTraitNames[T];
----------------
`ATT_Last` is also -1.


================
Comment at: clang/lib/Basic/TypeTraits.cpp:69
+const char *clang::getTraitName(UnaryExprOrTypeTrait T) {
+  assert(T <= UETT_Last && "invalid enum value!");
+  return UnaryExprOrTypeTraitNames[T];
----------------
`UETT_Last` is also -1.


================
Comment at: clang/lib/Sema/SemaExpr.cpp:3974
     S.Diag(Loc, diag::ext_sizeof_alignof_function_type)
-      << TraitKind << ArgRange;
+        << getTraitSpelling(TraitKind) << ArgRange;
     return false;
----------------
I think the original code was a bit more clear; would it make sense to make the diagnostic engine aware of trait kinds so that it does this dance for you? (It may be overkill given that we don't pass `UnaryExprOrTypeTrait` objects to the diagnostic engine THAT often, but I'm curious what you think.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81455/new/

https://reviews.llvm.org/D81455





More information about the cfe-commits mailing list