diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2011-06-19 09:05:14 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2011-06-19 09:05:14 +0000 |
commit | 2af68e4761ed30181540dafb5572993daffa4910 (patch) | |
tree | a53c7e2d4eaf30c6511feb0524827b53d470e982 /test/SemaCXX/nullptr_in_arithmetic_ops.cpp | |
parent | e3d49b44ad0596b2998ecf2e7ca78d59188920e5 (diff) |
Add test cases for false positives on -Wnull-arithmetic from Richard
Trieu, and fix them by checking for array and function types as well as
pointer types.
I've added a predicate method on Type to bundle together the logic we're
using here: isPointerLikeType(). I'd welcome better names for this
predicate, this is the best I came up with. It's implemented as a switch
to be a touch lighter weight than all the chained isa<...> casts that
would result otherwise.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133383 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/nullptr_in_arithmetic_ops.cpp')
-rw-r--r-- | test/SemaCXX/nullptr_in_arithmetic_ops.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/test/SemaCXX/nullptr_in_arithmetic_ops.cpp b/test/SemaCXX/nullptr_in_arithmetic_ops.cpp index 350d18a13f..e839ed116f 100644 --- a/test/SemaCXX/nullptr_in_arithmetic_ops.cpp +++ b/test/SemaCXX/nullptr_in_arithmetic_ops.cpp @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -fblocks -std=c++0x -verify %s -void f() { +void foo() { int a; bool b; @@ -49,8 +49,9 @@ void f() { b = &a <= nullptr || nullptr <= &a || &a >= nullptr || nullptr >= &a; b = &a == nullptr || nullptr == &a || &a != nullptr || nullptr != &a; - b = 0 == a; - b = 0 == &a; + b = nullptr < nullptr || nullptr > nullptr; + b = nullptr <= nullptr || nullptr >= nullptr; + b = nullptr == nullptr || nullptr != nullptr; b = ((nullptr)) != a; // expected-error{{invalid operands to binary expression}} @@ -62,4 +63,11 @@ void f() { void (X::*d) (); d = nullptr; b = d == nullptr || nullptr == d || d != nullptr || nullptr != d; + + extern void e(); + b = e == nullptr || nullptr == e || e != nullptr || nullptr != e; + + int f[2]; + b = f == nullptr || nullptr == f || f != nullptr || nullptr != f; + b = "f" == nullptr || nullptr == "f" || "f" != nullptr || nullptr != "f"; } |