From: Nick Lewycky Date: Thu, 24 Jan 2013 02:03:08 +0000 (+0000) Subject: Start checking nonnull (as well as format and argument_with_type_tag) on X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9b7ea0d2cc86c949ed70ad810f51ff34c7ce2f83;p=clang Start checking nonnull (as well as format and argument_with_type_tag) on overloaded binary operators. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173315 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 91d02dacc8..e1c3d6839d 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -10336,6 +10336,13 @@ Sema::CreateOverloadedBinOp(SourceLocation OpLoc, FnDecl)) return ExprError(); + ArrayRef ArgsArray(Args, 2); + // Cut off the implicit 'this'. + if (isa(FnDecl)) + ArgsArray = ArgsArray.slice(1); + checkCall(FnDecl, ArgsArray, 0, isa(FnDecl), OpLoc, + TheCall->getSourceRange(), VariadicDoesNotApply); + return MaybeBindToTemporary(TheCall); } else { // We matched a built-in operator. Convert the arguments, then diff --git a/test/SemaCXX/attr-nonnull.cpp b/test/SemaCXX/attr-nonnull.cpp index 76e1b74068..8af49d9d29 100644 --- a/test/SemaCXX/attr-nonnull.cpp +++ b/test/SemaCXX/attr-nonnull.cpp @@ -40,3 +40,15 @@ void g() { f(static_cast(0)); // expected-warning{{null passed}} } } + +namespace test4 { +struct X { + bool operator!=(const void *) const __attribute__((nonnull(2))); +}; +bool operator==(const X&, const void *) __attribute__((nonnull(2))); + +void test(const X& x) { + (void)(x == 0); // expected-warning{{null passed}} + (void)(x != 0); // expected-warning{{null passed}} +} +}