]> granicus.if.org Git - clang/commit
Disallow using ObjC literals in direct comparisons (== and friends).
authorJordan Rose <jordan_rose@apple.com>
Fri, 8 Jun 2012 21:14:25 +0000 (21:14 +0000)
committerJordan Rose <jordan_rose@apple.com>
Fri, 8 Jun 2012 21:14:25 +0000 (21:14 +0000)
commit9f63a451b1b3e36c0c82fcfe78828182bb9a6fa0
treec4a00296a42e178095f01242bb38117060909453
parent3772c9abf9651da1f77c83ec937c96e10a353c6a
Disallow using ObjC literals in direct comparisons (== and friends).

Objective-C literals conceptually always create new objects, but may be
optimized by the compiler or runtime (constant folding, singletons, etc).
Comparing addresses of these objects is relying on this optimization
behavior, which is really an implementation detail.

In the case of == and !=, offer a fixit to a call to -isEqual:, if the
method is available. This fixit is directly on the error so that it is
automatically applied.

Most of the time, this is really a newbie mistake, hence the fixit.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158230 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/AST/NSAPI.h
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/FixIt/objc-literals.m
test/SemaObjC/objc-literal-comparison.m [new file with mode: 0644]