-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Carving out -Wformat warning about scoped enums into a subwarning #81647
Comments
(naively, it seemed from the llvm docs like this was meant to be in |
From some of the descriptions in #38717 (comment) it sounds pretty bad to ignore this warning (like UB bad), if I'm understanding/following correctly? So I'm not sure demoting this to Perhaps in the cases where the underlying type of the scoped enum /does/ do the right thing, we could demote to |
seems like it's probably accidental UB though, because no-one thought to update the relevant part of the spec? there's no reason given for this, just an absence of explicit text saying "do the right thing"?
yeah, it'll be tricky to get a complete list (because we'd need to enable |
Enable There are 676 warnings. For 8- or 16-bit types: For non-8- or non-16-bit types: Only 2 warnings in |
Not implicitly promoting scoped enums is intentional, see https://cplusplus.github.io/CWG/issues/2347.html |
I would very much like to see this split out to a separate warning. We use enum class types in many places (strong typing) and this triggers many new warnings that are not present in MSVC. I'm not an expert at reading standard meeting notes but the last entry says this is "conditionally-supported with implementation-defined semantics." That does not sound like UB to me. Please move this warning to -Wformat-pedantic or similar solution. For now I have disabled format warnings because the static_cast<> cause unnecessary readability issues, and am depending on MSVC to catch format warnings. This is a shame because clang has helped us find and fix actual format issues. |
That's describing what happens when you pass a scoped enum to a varargs function. If it's supported, then you can pass them in and get them back again with |
Nor would it know what to do with it anyway. But it does know what to do with an enum's underlying type. And I have a hard time accepting Frankly, I'd be very happy if this validation allowed also "wrapper" structs with a single member matching the format, too. For exactly the same reasons. Such structs are sometimes used (as strong enums are) to create strongly-typed numeric-like types. I'm all for moving all such "reasonably safe" validations to only get flagged by a "-Wformat-pedantic". |
As a further migration pain here, Apple's Related issue that's not UB-level here, but the |
It's UB to pass a scoped enumeration to That said, having a separate subwarning to give users control over this has some appeal. We have |
@AaronBallman The UB argument is well understood and clang's strictness has proven to be a useful tool, at least for us, in keeping our code most portable. I don't want to discourage this sort of strictness improvement. But as discussed here the broadness of Arguably the best workaround of all would be to avoid the |
After thinking about it some more, I think I agree that |
Make it part of -Wformat-pedantic. Fixes llvm#81647
Make it part of -Wformat-pedantic. Fixes llvm#81647
Make it part of -Wformat-pedantic. Fixes llvm#81647
Make it part of -Wformat-pedantic. Fixes llvm#81647
Make it part of -Wformat-pedantic. Fixes llvm#81647
Make it part of -Wformat-pedantic. Fixes llvm#81647
…vm#88595) Make it part of -Wformat-pedantic. Fixes llvm#81647 (cherry picked from commit 73ed215)
Android uses -Wformat by default. Starting with 3632e2f517, this warning reports a lot of conversion warnings for scoped enums. It is infeasible to fix these in our third party code.
We can create a sub-warning, similar to other named diagnostics controlled by -Wformat (https://clang.llvm.org/docs/DiagnosticsReference.html#wformat), to be able to disable it selectivey for our third-party code.
@AaronBallman does this option sound good?
(cc: @enh-google @ZijunZhaoCCK )
The text was updated successfully, but these errors were encountered: