]> granicus.if.org Git - clang/commitdiff
fix __attribute__(format) for struct function pointer fields
authorNuno Lopes <nunoplopes@sapo.pt>
Fri, 18 Apr 2008 22:43:39 +0000 (22:43 +0000)
committerNuno Lopes <nunoplopes@sapo.pt>
Fri, 18 Apr 2008 22:43:39 +0000 (22:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49938 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/format-attribute.c

index 015ba8c65d9e62ef52166a9ae9454abea70af379..e51b7974aec8d16f8fe48adf99ed9c282831b3a0 100644 (file)
@@ -2268,10 +2268,14 @@ void Sema::HandleNothrowAttribute(Decl *d, AttributeList *rawAttr) {
 }
 
 static const FunctionTypeProto *getFunctionProto(Decl *d) {
-  ValueDecl *decl = dyn_cast<ValueDecl>(d);
-  if (!decl) return 0;
+  QualType Ty;
 
-  QualType Ty = decl->getType();
+  if (ValueDecl *decl = dyn_cast<ValueDecl>(d))
+    Ty = decl->getType();
+  else if (FieldDecl *decl = dyn_cast<FieldDecl>(d))
+    Ty = decl->getType();
+  else
+    return 0;
 
   if (Ty->isFunctionPointerType()) {
     const PointerType *PtrTy = Ty->getAsPointerType();
index df3e4b59591f4687211b87c66871eb85788819c0..8eefe3f0654461142f4bd7b0975933495b3d48ed 100644 (file)
@@ -17,3 +17,8 @@ void z(char *str, int c, ...) __attribute__((format(strftime, 1,2))); // expecte
 
 int (*f_ptr)(char*,...) __attribute__((format(printf, 1,2))); // no-error
 int (*f2_ptr)(double,...) __attribute__((format(printf, 1, 2))); // expected-error {{format argument not a string type}}
+
+struct _mystruct {
+  int (*printf)(const char *format, ...) __attribute__((__format__(printf, 1, 2))); // no-error
+  int (*printf2)(double format, ...) __attribute__((__format__(printf, 1, 2))); // expected-error {{format argument not a string type}}
+};