This is an archive of the discontinued LLVM Phabricator instance.

[ObjC] Add a warning for implicit conversions of a constant non-boolean value to BOOL
ClosedPublic

Authored by erik.pilkington on Jun 27 2019, 5:27 PM.

Details

Summary

On macOS, BOOL is a typedef for signed char, but it should never hold a value that isn't 1 or 0. Any code that expects a different value in their BOOL should be fixed. See also D63856.

rdar://problem/51954400 ObjC: Add diagnostics to catch incorrect usage of BOOL

Diff Detail

Repository
rL LLVM

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptJun 27 2019, 5:27 PM
rjmccall added inline comments.Jul 8 2019, 1:37 PM
clang/include/clang/Basic/DiagnosticSemaKinds.td
3251 ↗(On Diff #206973)

The from seems awkward here; %0 is the number, not the type. (I agree that the type isn't important for the diagnostic.)

Thoughts about this being in a sub-group? I'm not sure either way.

erik.pilkington marked 2 inline comments as done.

Address review comments.

clang/include/clang/Basic/DiagnosticSemaKinds.td
3251 ↗(On Diff #206973)

How about: "implicit conversion from constant value 42 to BOOL; ..."? I guess this is different enough from the other -Wconstant-conversion diagnostics to get a subgroup, so I added one in the new patch.

rjmccall accepted this revision.Jul 8 2019, 5:30 PM
rjmccall added inline comments.
clang/include/clang/Basic/DiagnosticSemaKinds.td
3251 ↗(On Diff #206973)

SGTM

This revision is now accepted and ready to land.Jul 8 2019, 5:30 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 9 2019, 10:29 AM