[PATCH] D142826: [Clang] Add -Wtype-limits to -Wextra for GCC compatibility

Haowei Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 7 14:45:16 PST 2023


haowei added a comment.

There are also cases that this clang type-limit check will warn when checking if a enum type is larger than 0. For example, we are seeing warnings on ICU source code (https://github.com/unicode-org/icu/blob/8d5a97ae0f49f6974372736ca67db15c37522f6f/icu4c/source/i18n/displayoptions.cpp#L79) after this patch was landed.

  U_CAPI const char * U_EXPORT2
  udispopt_getGrammaticalCaseIdentifier(UDisplayOptionsGrammaticalCase grammaticalCase) {
      if (grammaticalCase >= 0 && grammaticalCase < UPRV_LENGTHOF(grammaticalCaseIds)) {
          return grammaticalCaseIds[grammaticalCase];
      }
  
      return grammaticalCaseIds[0];
  }

grammaticalCase is a enum. And whether enum type is unsigned or not does not seem to be strictly defined in C/C++ standard, it ups to the compiler to decide how enum type should be defined. In that case, this check is legit and shouldn't trigger an warning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142826



More information about the cfe-commits mailing list