diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2013-02-01 20:04:49 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2013-02-01 20:04:49 +0000 |
commit | 41f7b1a854362f7de5cb6d6b0c2964373dede51d (patch) | |
tree | d3cab4c7810a9932622910def2132e316ac01b8c | |
parent | 8c888b10fdd2846885e8582b131fa076ce1b77b1 (diff) |
objc: Provide correct fixit instruction when two mismatched
nsstringis are compared without. // rdar://12716301
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174214 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 5 | ||||
-rw-r--r-- | test/FixIt/fixit-nsstring-compare.m | 22 |
2 files changed, 25 insertions, 2 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 6c76725880..2167f01b63 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -6964,11 +6964,12 @@ static void diagnoseObjCLiteralComparison(Sema &S, SourceLocation Loc, hasIsEqualMethod(S, LHS.get(), RHS.get())) { SourceLocation Start = LHS.get()->getLocStart(); SourceLocation End = S.PP.getLocForEndOfToken(RHS.get()->getLocEnd()); - SourceRange OpRange(Loc, S.PP.getLocForEndOfToken(Loc)); + CharSourceRange OpRange = + CharSourceRange::getCharRange(Loc, S.PP.getLocForEndOfToken(Loc)); S.Diag(Loc, diag::note_objc_literal_comparison_isequal) << FixItHint::CreateInsertion(Start, Opc == BO_EQ ? "[" : "![") - << FixItHint::CreateReplacement(OpRange, "isEqual:") + << FixItHint::CreateReplacement(OpRange, " isEqual:") << FixItHint::CreateInsertion(End, "]"); } } diff --git a/test/FixIt/fixit-nsstring-compare.m b/test/FixIt/fixit-nsstring-compare.m new file mode 100644 index 0000000000..6f0877c059 --- /dev/null +++ b/test/FixIt/fixit-nsstring-compare.m @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fdiagnostics-parseable-fixits -x objective-c %s 2>&1 | FileCheck %s +// rdar://12716301 + +typedef unsigned char BOOL; + +@protocol NSObject +- (BOOL)isEqual:(id)object; +@end + +@interface NSString<NSObject> +@end + +int main() { + NSString *stringA = @"stringA"; + + BOOL comparison = stringA==@"stringB"; + +} + +// CHECK: {16:21-16:21}:"[" +// CHECK: {16:28-16:30}:" isEqual:" +// CHECK: {16:40-16:40}:"]" |