From 8df014e2b173f9c0595f87480d59caaf8979fca3 Mon Sep 17 00:00:00 2001 From: Jean-Daniel Dupas Date: Wed, 17 Jul 2013 18:17:14 +0000 Subject: [PATCH] Improve idiomatic-parentheses by checking method family instead of relying on the selector name. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186524 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 2 +- test/SemaObjC/idiomatic-parentheses.m | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 517afdac1a..0106232bbb 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -11968,7 +11968,7 @@ void Sema::DiagnoseAssignmentAsCondition(Expr *E) { Selector Sel = ME->getSelector(); // self = [ init...] - if (isSelfExpr(Op->getLHS()) && Sel.getNameForSlot(0).startswith("init")) + if (isSelfExpr(Op->getLHS()) && ME->getMethodFamily() == OMF_init) diagnostic = diag::warn_condition_is_idiomatic_assignment; // = [ nextObject] diff --git a/test/SemaObjC/idiomatic-parentheses.m b/test/SemaObjC/idiomatic-parentheses.m index 801db5944f..c6281f0987 100644 --- a/test/SemaObjC/idiomatic-parentheses.m +++ b/test/SemaObjC/idiomatic-parentheses.m @@ -9,6 +9,7 @@ } - (id) init; - (id) initWithInt: (int) i; +- (id) myInit __attribute__((objc_method_family(init))); - (void) iterate: (id) coll; - (id) nextObject; @property unsigned uid; @@ -34,6 +35,12 @@ return self; } +- (id) myInit { + if (self = [self myInit]) { + } + return self; +} + - (void) iterate: (id) coll { id cur; while (cur = [coll nextObject]) { -- 2.40.0