]> granicus.if.org Git - clang/commitdiff
-Wobjc-literal-compare: look through implicit casts.
authorJordan Rose <jordan_rose@apple.com>
Fri, 9 Nov 2012 23:55:21 +0000 (23:55 +0000)
committerJordan Rose <jordan_rose@apple.com>
Fri, 9 Nov 2012 23:55:21 +0000 (23:55 +0000)
This warning was failing to fire under ARC because of the implicit
lifetime casts added around the object literal expression.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167648 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaObjC/objc-literal-comparison.m

index 28a637180a537aa8ea6bbdc04df6b8d571f0d1a0..bf4abfcb74604eea907a98dd38c02afd008e936f 100644 (file)
@@ -6783,7 +6783,7 @@ static void diagnoseFunctionPointerToVoidComparison(Sema &S, SourceLocation Loc,
 }
 
 static bool isObjCObjectLiteral(ExprResult &E) {
-  switch (E.get()->getStmtClass()) {
+  switch (E.get()->IgnoreParenImpCasts()->getStmtClass()) {
   case Stmt::ObjCArrayLiteralClass:
   case Stmt::ObjCDictionaryLiteralClass:
   case Stmt::ObjCStringLiteralClass:
@@ -6875,6 +6875,7 @@ static void diagnoseObjCLiteralComparison(Sema &S, SourceLocation Loc,
     LK_String
   } LiteralKind;
 
+  Literal = Literal->IgnoreParenImpCasts();
   switch (Literal->getStmtClass()) {
   case Stmt::ObjCStringLiteralClass:
     // "string literal"
index f1aa8ecd91e22066f5a8dbfd4d8f8baf457f7b74..0a1058291e4e93814b01964f32fb7a807db470eb 100644 (file)
@@ -2,6 +2,10 @@
 // RUN: %clang_cc1 -fsyntax-only -Wno-everything -Wobjc-literal-compare "-Dnil=(id)0" -verify %s
 // RUN: %clang_cc1 -fsyntax-only -Wno-everything -Wobjc-literal-compare "-Dnil=0" -verify %s
 
+// RUN: %clang_cc1 -fsyntax-only -Wno-everything -Wobjc-literal-compare -fobjc-arc "-Dnil=((id)0)" -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-everything -Wobjc-literal-compare -fobjc-arc "-Dnil=(id)0" -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-everything -Wobjc-literal-compare -fobjc-arc "-Dnil=0" -verify %s
+
 // (test the warning flag as well)
 
 typedef signed char BOOL;