[PATCH] D15935: Improve diagnostics for literal conversion to Boolean

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 6 13:17:22 PST 2016


aaron.ballman created this revision.
aaron.ballman added reviewers: rsmith, dblaikie.
aaron.ballman added a subscriber: cfe-commits.

This patch improves the literal conversion diagnostics where the target type is a Boolean by handling literals more consistently, and telling the user whether the resulting value will be true or false.

This patch changes the behavior of literal conversions from floating-point literals in two ways: (1) we now always diagnose instead of silently accepting conversions where the float can be converted to an exact integer value, and (2) we drop the information about what the source value of the floating-point literal is (it's unimportant information in the context of the Boolean conversion).

This patch removes the string literal conversion diagnostic (and -Wstring-conversion) which is off by default, and rolls its functionality into -Wliteral-conversion, which is on by default. Since we already handle string literal to bool conversion through logical && to not diagnose, I do not believe this will increase the chattiness of the diagnostic. In fact, turning the diagnostic to on by default caught a few tests that were accidentally using string->bool literal conversions. This does change the wording of the previous diagnostic, but I think the new wording is an improvement.

This patch now diagnoses character literal conversions to Boolean types where they used to be silently accepted.

http://reviews.llvm.org/D15935

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/Analysis/casts.c
  test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
  test/CXX/expr/expr.unary/expr.unary.op/p6.cpp
  test/Sema/exprs.c
  test/Sema/warn-string-conversion.c
  test/SemaCXX/condition.cpp
  test/SemaCXX/overload-call.cpp
  test/SemaCXX/warn-literal-conversion.cpp
  test/SemaCXX/warn-string-conversion.cpp
  test/SemaCXX/warn-thread-safety-analysis.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15935.44150.patch
Type: text/x-patch
Size: 17281 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160106/5b7643ad/attachment-0001.bin>


More information about the cfe-commits mailing list