]> granicus.if.org Git - clang/commitdiff
Start checking nonnull (as well as format and argument_with_type_tag) on
authorNick Lewycky <nicholas@mxc.ca>
Thu, 24 Jan 2013 02:03:08 +0000 (02:03 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Thu, 24 Jan 2013 02:03:08 +0000 (02:03 +0000)
overloaded binary operators.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173315 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaOverload.cpp
test/SemaCXX/attr-nonnull.cpp

index 91d02dacc82d10ae859dd9c6bd2b6176e10b8086..e1c3d6839d1148371aca5356273f65f1ee8bea96 100644 (file)
@@ -10336,6 +10336,13 @@ Sema::CreateOverloadedBinOp(SourceLocation OpLoc,
                                 FnDecl))
           return ExprError();
 
+        ArrayRef<const Expr *> ArgsArray(Args, 2);
+        // Cut off the implicit 'this'.
+        if (isa<CXXMethodDecl>(FnDecl))
+          ArgsArray = ArgsArray.slice(1);
+        checkCall(FnDecl, ArgsArray, 0, isa<CXXMethodDecl>(FnDecl), OpLoc, 
+                  TheCall->getSourceRange(), VariadicDoesNotApply);
+
         return MaybeBindToTemporary(TheCall);
       } else {
         // We matched a built-in operator. Convert the arguments, then
index 76e1b74068cc1ffb2e9575f02654059256451985..8af49d9d29e609ce3020e660ddb1eaa81a94a5a9 100644 (file)
@@ -40,3 +40,15 @@ void g() {
   f(static_cast<char*>(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}}
+}
+}