[cfe-commits] r107450 - /cfe/trunk/include/clang/AST/RecursiveASTVisitor.h

Craig Silverstein csilvers2000 at yahoo.com
Thu Jul 1 16:46:26 PDT 2010


Author: csilvers
Date: Thu Jul  1 18:46:26 2010
New Revision: 107450

URL: http://llvm.org/viewvc/llvm-project?rev=107450&view=rev
Log:
Handle typedef function declarations correctly, such as
       typedef int (*Myfunc)(int);
       Myfunc func;

Reviewed by chandlerc

Modified:
    cfe/trunk/include/clang/AST/RecursiveASTVisitor.h

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=107450&r1=107449&r2=107450&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Thu Jul  1 18:46:26 2010
@@ -977,17 +977,23 @@
   TRY_TO(TraverseNestedNameSpecifier(D->getQualifier()));
 
   // Visit the function type itself, which can be either
-  // FunctionNoProtoType or FunctionProtoType.
+  // FunctionNoProtoType or FunctionProtoType, or a typedef.  If it's
+  // not a Function*ProtoType, then it can't have a body or arguments,
+  // so we have to do less work.
   Type *FuncType = D->getType().getTypePtr();
-  if (FunctionNoProtoType *FuncNoProto =
+  if (FunctionProtoType *FuncProto = dyn_cast<FunctionProtoType>(FuncType)) {
+    // Don't call Traverse*, or the result type and parameter types
+    // will be double counted.
+    TRY_TO(WalkUpFromFunctionProtoType(FuncProto));
+  } else if (FunctionNoProtoType *FuncNoProto =
       dyn_cast<FunctionNoProtoType>(FuncType)) {
     // Don't call Traverse*, or the result type will be double
     // counted.
     TRY_TO(WalkUpFromFunctionNoProtoType(FuncNoProto));
-  } else {
-    // Don't call Traverse*, or the result type and parameter types
-    // will be double counted.
-    TRY_TO(WalkUpFromFunctionProtoType(dyn_cast<FunctionProtoType>(FuncType)));
+  } else {   // a typedef type, or who knows what
+    TRY_TO(TraverseType(D->getType()));
+    assert(!D->isThisDeclarationADefinition() && "Unexpected function type");
+    return true;
   }
 
   TRY_TO(TraverseType(D->getResultType()));





More information about the cfe-commits mailing list