From 9263a3060087eb7b5954ec4ee1ff2c22227b422e Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Tue, 16 Nov 2010 08:49:43 +0000 Subject: [PATCH] Fix PR8625 and correctly interpret member-calls to static members when producing warnings. This feels really fragile, and I've not audited all other argument index-based warnings. I suspect we'll grow this bug on another warning eventually. It might be nice to adjust the argument indices when building up the attribute AST node, as we already have to remember about the 'this' argument within that code to produce correct errors. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119340 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaChecking.cpp | 16 ++++++++++------ test/SemaCXX/attr-format.cpp | 14 +++++++++++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 83d7c0760e..bce28c2c91 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -1090,12 +1090,16 @@ Sema::CheckPrintfScanfArguments(const CallExpr *TheCall, bool HasVAListArg, // of member functions is counted. However, it doesn't appear in our own // lists, so decrement format_idx in that case. if (isa(TheCall)) { - // Catch a format attribute mistakenly referring to the object argument. - if (format_idx == 0) - return; - --format_idx; - if(firstDataArg != 0) - --firstDataArg; + const CXXMethodDecl *method_decl = + dyn_cast(TheCall->getCalleeDecl()); + if (method_decl && method_decl->isInstance()) { + // Catch a format attribute mistakenly referring to the object argument. + if (format_idx == 0) + return; + --format_idx; + if(firstDataArg != 0) + --firstDataArg; + } } // CHECK: printf/scanf-like function is called with no format string. diff --git a/test/SemaCXX/attr-format.cpp b/test/SemaCXX/attr-format.cpp index bf13149600..da134a136d 100644 --- a/test/SemaCXX/attr-format.cpp +++ b/test/SemaCXX/attr-format.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wformat-nonliteral -verify %s struct S { static void f(const char*, ...) __attribute__((format(printf, 1, 2))); static const char* f2(const char*) __attribute__((format_arg(1))); @@ -21,3 +21,15 @@ struct A { void a(const char*,...) __attribute((format(printf,2,3))); }; void b(A x) { x.a("%d", 3); } + +// PR8625: correctly interpret static member calls as not having an implicit +// 'this' argument. +namespace PR8625 { + struct S { + static void f(const char*, const char*, ...) + __attribute__((format(printf, 2, 3))); + }; + void test(S s, const char* str) { + s.f(str, "%s", str); + } +} -- 2.40.0