]> granicus.if.org Git - clang/commit
PR16074, implement warnings to catch pointer to boolean true and pointer to
authorRichard Trieu <rtrieu@google.com>
Wed, 26 Feb 2014 02:36:06 +0000 (02:36 +0000)
committerRichard Trieu <rtrieu@google.com>
Wed, 26 Feb 2014 02:36:06 +0000 (02:36 +0000)
commit2a66e6e50046e6b9ae048f114ad4fec23011e93c
tree6c3d809f806b0d53a9c0a9ed9946a2f674cfef53
parente1805368a8a09000b3be70b50e20522efb78581e
PR16074, implement warnings to catch pointer to boolean true and pointer to
null comparison when the pointer is known to be non-null.

This catches the array to pointer decay, function to pointer decay and
address of variables.  This does not catch address of function since this
has been previously used to silence a warning.

Pointer to bool conversion is under -Wbool-conversion.
Pointer to null comparison is under -Wtautological-pointer-compare, a sub-group
of -Wtautological-compare.

void foo() {
  int arr[5];
  int x;
  // warn on these conditionals
  if (foo);
  if (arr);
  if (&x);
  if (foo == null);
  if (arr == null);
  if (&x == null);

  if (&foo);  // no warning
}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202216 91177308-0d34-0410-b5e6-96231b3b80d8
21 files changed:
include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Sema/Sema.h
lib/Sema/SemaChecking.cpp
lib/Sema/SemaExpr.cpp
test/Analysis/casts.c
test/Analysis/ptr-arith.c
test/Analysis/stackaddrleak.c
test/Analysis/weak-functions.c
test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-cxx11-nowarn.cpp
test/CXX/expr/expr.unary/expr.unary.op/p6.cpp
test/Sema/const-eval.c
test/Sema/static-init.c
test/SemaCXX/constant-expression-cxx11.cpp
test/SemaCXX/null_in_arithmetic_ops.cpp
test/SemaCXX/nullptr_in_arithmetic_ops.cpp
test/SemaCXX/warn-bool-conversion.cpp
test/SemaCXX/warn-func-as-bool.cpp [deleted file]
test/SemaCXX/warn-tautological-compare.cpp
test/SemaTemplate/resolve-single-template-id.cpp