diff options
author | Ted Kremenek <kremenek@apple.com> | 2012-12-21 21:59:39 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2012-12-21 21:59:39 +0000 |
commit | f530ff76de3b270f2287d3555d93b5d270643eeb (patch) | |
tree | acf27a4fab5571d695a29f698f416f282a8bbd8b /lib/Sema/SemaChecking.cpp | |
parent | 3ee069bddb538ebafff2068e99136cc526fb9fdd (diff) |
Change checkUnsafeAssignLiteral() to use the new Sema::CheckLiteralKind().
Along the way, fix a bug in CheckLiteralKind(), previously in diagnoseObjCLiteralComparison, where we didn't ignore parentheses
in boxed expressions for purpose of classification.
In other words, both @42 and @(42) should be classified as numeric
literals.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170931 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index c2dabb45af..7d957ec408 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -5753,33 +5753,24 @@ static bool checkUnsafeAssignLiteral(Sema &S, SourceLocation Loc, // immediately zapped in a weak reference. Note that we explicitly // allow ObjCStringLiterals, since those are designed to never really die. RHS = RHS->IgnoreParenImpCasts(); - // This enum needs to match with the 'select' in warn_arc_literal_assign. - enum Kind { Dictionary = 0, Array, Block, BoxedE, None }; - unsigned kind = None; - switch (RHS->getStmtClass()) { - default: - break; - case Stmt::ObjCDictionaryLiteralClass: - kind = Dictionary; - break; - case Stmt::ObjCArrayLiteralClass: - kind = Array; - break; - case Stmt::BlockExprClass: - kind = Block; - break; - case Stmt::ObjCBoxedExprClass: - kind = BoxedE; - break; + + // Classification for diagnostic. + unsigned SelectVal = /* block literal */ 0; + if (!isa<BlockExpr>(RHS)) { + // This enum needs to match with the 'select' in + // warn_objc_arc_literal_assign (off-by-1). + Sema::ObjCLiteralKind Kind = S.CheckLiteralKind(RHS); + if (Kind == Sema::LK_String || Kind == Sema::LK_None) + return false; + SelectVal = (unsigned) Kind + 1; } - if (kind != None) { - S.Diag(Loc, diag::warn_arc_literal_assign) - << (unsigned) kind + + S.Diag(Loc, diag::warn_arc_literal_assign) + << SelectVal << (isProperty ? 0 : 1) << RHS->getSourceRange(); - return true; - } - return false; + + return true; } static bool checkUnsafeAssignObject(Sema &S, SourceLocation Loc, |