r235606 - Extend format specifier checking to include field function pointers in addition to variable function pointers. Addresses PR21082.
Aaron Ballman
aaron at aaronballman.com
Thu Apr 23 09:14:19 PDT 2015
Author: aaronballman
Date: Thu Apr 23 11:14:19 2015
New Revision: 235606
URL: http://llvm.org/viewvc/llvm-project?rev=235606&view=rev
Log:
Extend format specifier checking to include field function pointers in addition to variable function pointers. Addresses PR21082.
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaCXX/format-strings.cpp
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=235606&r1=235605&r2=235606&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Apr 23 11:14:19 2015
@@ -1289,11 +1289,14 @@ bool Sema::CheckObjCMethodCall(ObjCMetho
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;
Modified: cfe/trunk/test/SemaCXX/format-strings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/format-strings.cpp?rev=235606&r1=235605&r2=235606&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/format-strings.cpp (original)
+++ cfe/trunk/test/SemaCXX/format-strings.cpp Thu Apr 23 11:14:19 2015
@@ -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}}
+}
+}
More information about the cfe-commits
mailing list