[PATCH] D153623: [clang][Sema] Add fixit for scoped enum format error

Shoaib Meenai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 26 15:31:19 PDT 2023


smeenai added a comment.

Sorry for the delayed comment here.

The fix-it is convenient, but is it the best suggestion? It'll end up suggesting truncating the enum value instead of using the proper format specifier in https://godbolt.org/z/xdhrefG95, for example. More insidiously, the `static_cast` might work fine for all enum uses today but silently cause issues for future enum values.

Using `std::to_underyling` and matching the format specifier to the underlying type would be the best suggestion IMO, but that only works in C++23 and above :( I guess `std::underlying_type_t` isn't super ugly either for C++14 and above, but bare `std::underlying_type` is pretty rough to use in a cast. All of those require the addition of a header though, and I'm not sure if that's acceptable for a fix-it.

Would we at least consider suggesting a format specifier and cast based on the underlying type of the enum, instead of just casting to whatever type the format specifier was using? That won't guard against future changes to the enum, but it's better than the status quo IMO.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153623



More information about the cfe-commits mailing list