@@ -1459,21 +1459,20 @@ bool Sema::SemaCheckStringLiteral(const Expr *E, Expr **Args,
1459
1459
return false ;
1460
1460
}
1461
1461
1462
- case Stmt::CallExprClass: {
1462
+ case Stmt::CallExprClass:
1463
+ case Stmt::CXXMemberCallExprClass: {
1463
1464
const CallExpr *CE = cast<CallExpr>(E);
1464
- if (const ImplicitCastExpr *ICE
1465
- = dyn_cast<ImplicitCastExpr>(CE->getCallee ())) {
1466
- if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr ())) {
1467
- if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(DRE->getDecl ())) {
1468
- if (const FormatArgAttr *FA = FD->getAttr <FormatArgAttr>()) {
1469
- unsigned ArgIndex = FA->getFormatIdx ();
1470
- const Expr *Arg = CE->getArg (ArgIndex - 1 );
1471
-
1472
- return SemaCheckStringLiteral (Arg, Args, NumArgs, HasVAListArg,
1473
- format_idx, firstDataArg, Type,
1474
- inFunctionCall);
1475
- }
1476
- }
1465
+ if (const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(CE->getCalleeDecl ())) {
1466
+ if (const FormatArgAttr *FA = ND->getAttr <FormatArgAttr>()) {
1467
+ unsigned ArgIndex = FA->getFormatIdx ();
1468
+ if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(ND))
1469
+ if (MD->isInstance ())
1470
+ --ArgIndex;
1471
+ const Expr *Arg = CE->getArg (ArgIndex - 1 );
1472
+
1473
+ return SemaCheckStringLiteral (Arg, Args, NumArgs, HasVAListArg,
1474
+ format_idx, firstDataArg, Type,
1475
+ inFunctionCall);
1477
1476
}
1478
1477
}
1479
1478
@@ -1534,11 +1533,7 @@ void Sema::CheckFormatArguments(const FormatAttr *Format, CallExpr *TheCall) {
1534
1533
// The way the format attribute works in GCC, the implicit this argument
1535
1534
// of member functions is counted. However, it doesn't appear in our own
1536
1535
// lists, so decrement format_idx in that case.
1537
- if (isa<CXXMemberCallExpr>(TheCall)) {
1538
- const CXXMethodDecl *method_decl =
1539
- dyn_cast<CXXMethodDecl>(TheCall->getCalleeDecl ());
1540
- IsCXXMember = method_decl && method_decl->isInstance ();
1541
- }
1536
+ IsCXXMember = isa<CXXMemberCallExpr>(TheCall);
1542
1537
CheckFormatArguments (Format, TheCall->getArgs (), TheCall->getNumArgs (),
1543
1538
IsCXXMember, TheCall->getRParenLoc (),
1544
1539
TheCall->getCallee ()->getSourceRange ());
0 commit comments