Index: test/Sema/fn-ptr-as-fn-prototype.c
===================================================================
--- test/Sema/fn-ptr-as-fn-prototype.c	(revision 0)
+++ test/Sema/fn-ptr-as-fn-prototype.c	(revision 0)
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1_only -ast-print %s | FileCheck %s
+
+// This testcase checks the functionality of 
+// Sema::ActOn{Start,End}FunctionDeclarator, specifically checking that
+// ActOnEndFunctionDeclarator is called after the typedef so the enum
+// is in the global scope, not the scope of f().
+
+// CHECK: typedef void (*g)();
+typedef void (*g) ();
+// CHECK: enum {
+enum {
+  k = -1
+};
+// CHECK: void f() {
+void f() {}

Property changes on: test/Sema/fn-ptr-as-fn-prototype.c
___________________________________________________________________
Added: svn:eol-style
   + native

Index: test/CodeGen/decl-in-prototype.c
===================================================================
--- test/CodeGen/decl-in-prototype.c	(revision 151638)
+++ test/CodeGen/decl-in-prototype.c	(working copy)
@@ -13,3 +13,9 @@
     // CHECK: ret i32 7
     return AA;
 }
+
+// Check nested function declarators work.
+int f(void (*g)(), enum {AA,BB} h) {
+    // CHECK: ret i32 0
+    return AA;
+}
Index: include/clang/Sema/Sema.h
===================================================================
--- include/clang/Sema/Sema.h	(revision 151638)
+++ include/clang/Sema/Sema.h	(working copy)
@@ -907,7 +907,11 @@
   /// function to pin them on. ActOnFunctionDeclarator reads this list and patches
   /// them into the FunctionDecl.
   std::vector<NamedDecl*> DeclsInPrototypeScope;
-  bool InFunctionDeclarator;
+  /// Nonzero if we are currently parsing a function declarator. This is a counter
+  /// as opposed to a boolean so we can deal with nested function declarators
+  /// such as:
+  ///     void f(void (*g)(), ...)
+  unsigned InFunctionDeclarator;
 
   DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = 0);
 
@@ -1056,6 +1060,7 @@
   bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous);
   void CheckCompleteVariableDeclaration(VarDecl *var);
   void ActOnStartFunctionDeclarator();
+  void ActOnEndFunctionDeclarator();
   NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
                                      TypeSourceInfo *TInfo,
                                      LookupResult &Previous,
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp	(revision 151641)
+++ lib/Sema/SemaDecl.cpp	(working copy)
@@ -1250,9 +1250,14 @@
 }
 
 void Sema::ActOnStartFunctionDeclarator() {
-  InFunctionDeclarator = true;
+  ++InFunctionDeclarator;
 }
 
+void Sema::ActOnEndFunctionDeclarator() {
+  assert(InFunctionDeclarator);
+  --InFunctionDeclarator;
+}
+
 /// \brief Look for an Objective-C class in the translation unit.
 ///
 /// \param Id The name of the Objective-C class we're looking for. If
@@ -4814,8 +4819,6 @@
 
   assert(R.getTypePtr()->isFunctionType());
 
-  InFunctionDeclarator = false;
-
   // TODO: consider using NameInfo for diagnostic.
   DeclarationNameInfo NameInfo = GetNameForDeclarator(D);
   DeclarationName Name = NameInfo.getName();
Index: lib/Sema/Sema.cpp
===================================================================
--- lib/Sema/Sema.cpp	(revision 151638)
+++ lib/Sema/Sema.cpp	(working copy)
@@ -94,7 +94,7 @@
     ObjCShouldCallSuperDealloc(false),
     ObjCShouldCallSuperFinalize(false),
     TUKind(TUKind),
-    NumSFINAEErrors(0), InFunctionDeclarator(false), SuppressAccessChecking(false), 
+    NumSFINAEErrors(0), InFunctionDeclarator(0), SuppressAccessChecking(false), 
     AccessCheckingSFINAE(false), InNonInstantiationSFINAEContext(false),
     NonInstantiationEntries(0), ArgumentPackSubstitutionIndex(-1),
     CurrentInstantiationScope(0), TyposCorrected(0),
Index: lib/Parse/ParseDecl.cpp
===================================================================
--- lib/Parse/ParseDecl.cpp	(revision 151638)
+++ lib/Parse/ParseDecl.cpp	(working copy)
@@ -4310,6 +4310,8 @@
                                              EndLoc, D,
                                              TrailingReturnType),
                 attrs, EndLoc);
+
+  Actions.ActOnEndFunctionDeclarator();
 }
 
 /// isFunctionDeclaratorIdentifierList - This parameter list may have an
