summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2015-04-23 16:14:19 +0000
committerAaron Ballman <aaron@aaronballman.com>2015-04-23 16:14:19 +0000
commitb673c65cb2e98fb10fca106165a3df31d08be8b9 (patch)
treee56ee01492b2532b82920ea6dfb0b399594f09e8 /clang
parent1710cc994ecd3b422a54a35117b089adff4d42c1 (diff)
downloadbcm5719-llvm-b673c65cb2e98fb10fca106165a3df31d08be8b9.tar.gz
bcm5719-llvm-b673c65cb2e98fb10fca106165a3df31d08be8b9.zip
Extend format specifier checking to include field function pointers in addition to variable function pointers. Addresses PR21082.
llvm-svn: 235606
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/SemaChecking.cpp9
-rw-r--r--clang/test/SemaCXX/format-strings.cpp15
2 files changed, 21 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 05eaaec5792..fd91c77bf12 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -1289,11 +1289,14 @@ bool Sema::CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation lbrac,
bool Sema::CheckPointerCall(NamedDecl *NDecl, CallExpr *TheCall,
const FunctionProtoType *Proto) {
- const VarDecl *V = dyn_cast<VarDecl>(NDecl);
- if (!V)
+ QualType Ty;
+ if (const auto *V = dyn_cast<VarDecl>(NDecl))
+ Ty = V->getType();
+ else if (const auto *F = dyn_cast<FieldDecl>(NDecl))
+ Ty = F->getType();
+ else
return false;
- QualType Ty = V->getType();
if (!Ty->isBlockPointerType() && !Ty->isFunctionPointerType())
return false;
diff --git a/clang/test/SemaCXX/format-strings.cpp b/clang/test/SemaCXX/format-strings.cpp
index 41775708feb..fa7251d0dd7 100644
--- a/clang/test/SemaCXX/format-strings.cpp
+++ b/clang/test/SemaCXX/format-strings.cpp
@@ -133,3 +133,18 @@ namespace Templates {
}
}
+namespace implicit_this_tests {
+struct t {
+ void func1(const char *, ...) __attribute__((__format__(printf, 1, 2))); // expected-error {{format attribute cannot specify the implicit this argument as the format string}}
+ void (*func2)(const char *, ...) __attribute__((__format__(printf, 1, 2)));
+ static void (*func3)(const char *, ...) __attribute__((__format__(printf, 1, 2)));
+ static void func4(const char *, ...) __attribute__((__format__(printf, 1, 2)));
+};
+
+void f() {
+ t t1;
+ t1.func2("Hello %s"); // expected-warning {{more '%' conversions than data arguments}}
+ t::func3("Hello %s"); // expected-warning {{more '%' conversions than data arguments}}
+ t::func4("Hello %s"); // expected-warning {{more '%' conversions than data arguments}}
+}
+}
OpenPOWER on IntegriCloud