Commit Graph

7 Commits

Author SHA1 Message Date
Benjamin Kramer 25c0510690 Sema: Unnest early exit and remove an unnecessary bad cast.
cast<ObjCObjectPointerType> doesn't look through sugar, getAs does.
Fixes PR15257.

llvm-svn: 175272
2013-02-15 15:17:50 +00:00
Jordan Rose e2028139e9 -Wobjc-literal-compare: look through implicit casts.
This warning was failing to fire under ARC because of the implicit
lifetime casts added around the object literal expression.

<rdar://problem/11300873>, again.

llvm-svn: 167648
2012-11-09 23:55:21 +00:00
Jordan Rose 63ffaa8c18 -Wobjc-literal-compare: don't warn when comparing against nil.
Checks against nil often appear as guards in macros, and comparing
Objective-C literals to nil has well-defined behavior (if tautological).

On OS X, 'nil' has not been typed as 'id' since 10.6 (possibly earlier),
so the warning was already not firing, but other runtimes continue to use
((id)0) or some variant. This change accepts comparisons to any null pointer;
to keep it simple, it looks through all casts (not just casts to 'id').

PR13276

llvm-svn: 160379
2012-07-17 17:46:48 +00:00
Jordan Rose ea70bf7154 Add -Wobjc-string-compare under -Wobjc-literal-compare.
Suggested by Ted, since string literal comparison is at least slightly more
sensible than comparison of runtime literals. (Ambiguous language on
developer.apple.com implies that strings are guaranteed to be uniqued within
a translation unit and possibly across a linked binary.)

llvm-svn: 160378
2012-07-17 17:46:44 +00:00
Jordan Rose 7660f78fb9 Now that -Wobjc-literal-compare is a warning, put the fixit on a note.
Recovering as if the user had actually called -isEqual: is a bit too far from
the semantics of the program as written, /even though/ it's probably what they
intended.

llvm-svn: 160377
2012-07-17 17:46:40 +00:00
Jordan Rose f919803001 Downgrade the "direct comparison" error for ObjC literals to a warning.
Chris pointed out that while the comparison is certainly problematic
and does not have well-defined behavior, it isn't any worse than some
of the other abuses that we merely warn about and doesn't need to make
the compilation fail.

Revert the release notes change (r159766) now that this is just a new warning.

llvm-svn: 159939
2012-07-09 16:54:44 +00:00
Jordan Rose d49a33e86c 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.

llvm-svn: 158230
2012-06-08 21:14:25 +00:00