def warn_null_in_arithmetic_operation : Warning<
"use of NULL in arithmetic operation">,
InGroup<DiagGroup<"null-arithmetic">>;
+def warn_null_in_comparison_operation : Warning<
+ "comparison between NULL and non-pointer "
+ "%select{(%1 and NULL)|(NULL and %1)}0">,
+ InGroup<DiagGroup<"null-arithmetic">>;
def err_invalid_this_use : Error<
"invalid use of 'this' outside of a nonstatic member function">;
!LeftType->canDecayToPointerType() &&
!RightType->isAnyPointerType() &&
!RightType->canDecayToPointerType()) {
- Diag(OpLoc, diag::warn_null_in_arithmetic_operation)
- << (LeftNull ? lhs.get()->getSourceRange()
- : rhs.get()->getSourceRange());
+ Diag(OpLoc, diag::warn_null_in_comparison_operation)
+ << LeftNull /* LHS is NULL */
+ << (LeftNull ? rhs.get()->getType() : lhs.get()->getType())
+ << lhs.get()->getSourceRange() << rhs.get()->getSourceRange();
}
}
}
a |= NULL; // expected-warning{{use of NULL in arithmetic operation}}
a ^= NULL; // expected-warning{{use of NULL in arithmetic operation}}
- b = a < NULL || NULL < a; // expected-warning 2{{use of NULL in arithmetic operation}}
- b = a > NULL || NULL > a; // expected-warning 2{{use of NULL in arithmetic operation}}
- b = a <= NULL || NULL <= a; // expected-warning 2{{use of NULL in arithmetic operation}}
- b = a >= NULL || NULL >= a; // expected-warning 2{{use of NULL in arithmetic operation}}
- b = a == NULL || NULL == a; // expected-warning 2{{use of NULL in arithmetic operation}}
- b = a != NULL || NULL != a; // expected-warning 2{{use of NULL in arithmetic operation}}
+ b = a < NULL || a > NULL; // expected-warning 2{{comparison between NULL and non-pointer ('int' and NULL)}}
+ b = NULL < a || NULL > a; // expected-warning 2{{comparison between NULL and non-pointer (NULL and 'int')}}
+ b = a <= NULL || a >= NULL; // expected-warning 2{{comparison between NULL and non-pointer ('int' and NULL)}}
+ b = NULL <= a || NULL >= a; // expected-warning 2{{comparison between NULL and non-pointer (NULL and 'int')}}
+ b = a == NULL || a != NULL; // expected-warning 2{{comparison between NULL and non-pointer ('int' and NULL)}}
+ b = NULL == a || NULL != a; // expected-warning 2{{comparison between NULL and non-pointer (NULL and 'int')}}
b = &a < NULL || NULL < &a || &a > NULL || NULL > &a;
b = &a <= NULL || NULL <= &a || &a >= NULL || NULL >= &a;
b = NULL <= NULL || NULL >= NULL;
b = NULL == NULL || NULL != NULL;
- b = ((NULL)) != a; // expected-warning{{use of NULL in arithmetic operation}}
+ b = ((NULL)) != a; // expected-warning{{comparison between NULL and non-pointer (NULL and 'int')}}
// Check that even non-standard pointers don't warn.
b = c == NULL || NULL == c || c != NULL || NULL != c;