From: Aaron Ballman Date: Mon, 4 Aug 2014 15:26:33 +0000 (+0000) Subject: Highlight the offending function parameter when the format argument refers to an... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5f2d81841a6932aea4d989c46363b12207a263dc;p=clang Highlight the offending function parameter when the format argument refers to an invalid function parameter type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214723 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 4408abb7d8..a1afbdba7a 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -2545,23 +2545,24 @@ static void handleFormatAttr(Sema &S, Decl *D, const AttributeList &Attr) { if (Kind == CFStringFormat) { if (!isCFStringType(Ty, S.Context)) { S.Diag(Attr.getLoc(), diag::err_format_attribute_not) - << "a CFString" << IdxExpr->getSourceRange(); + << "a CFString" << IdxExpr->getSourceRange() + << getFunctionOrMethodParamRange(D, ArgIdx); return; } } else if (Kind == NSStringFormat) { // FIXME: do we need to check if the type is NSString*? What are the // semantics? if (!isNSStringType(Ty, S.Context)) { - // FIXME: Should highlight the actual expression that has the wrong type. S.Diag(Attr.getLoc(), diag::err_format_attribute_not) - << "an NSString" << IdxExpr->getSourceRange(); + << "an NSString" << IdxExpr->getSourceRange() + << getFunctionOrMethodParamRange(D, ArgIdx); return; } } else if (!Ty->isPointerType() || !Ty->getAs()->getPointeeType()->isCharType()) { - // FIXME: Should highlight the actual expression that has the wrong type. S.Diag(Attr.getLoc(), diag::err_format_attribute_not) - << "a string type" << IdxExpr->getSourceRange(); + << "a string type" << IdxExpr->getSourceRange() + << getFunctionOrMethodParamRange(D, ArgIdx); return; }