Index: src/GenPoly/Box.cc
===================================================================
--- src/GenPoly/Box.cc	(revision 637c139a9dc1ec8c55bede326c893f33fb83ccd1)
+++ src/GenPoly/Box.cc	(revision e3bf4cfe0cc353bcce1283a6aed6f23482eb5d2c)
@@ -68,8 +68,5 @@
 		/// Adds layout-generation functions to polymorphic types.
 		class LayoutFunctionBuilder final : public WithDeclsToAdd, public WithVisitorRef<LayoutFunctionBuilder>, public WithShortCircuiting {
-			// Current level of nested functions:
-			unsigned int functionNesting = 0;
 		public:
-			void previsit( FunctionDecl *functionDecl );
 			void previsit( StructDecl *structDecl );
 			void previsit( UnionDecl *unionDecl );
@@ -237,12 +234,4 @@
 	////////////////////////////////// LayoutFunctionBuilder ////////////////////////////////////////////
 
-	void LayoutFunctionBuilder::previsit( FunctionDecl *functionDecl ) {
-		visit_children = false;
-		maybeAccept( functionDecl->get_functionType(), *visitor );
-		++functionNesting;
-		maybeAccept( functionDecl->get_statements(), *visitor );
-		--functionNesting;
-	}
-
 	/// Get a list of type declarations that will affect a layout function
 	std::list< TypeDecl* > takeOtypeOnly( std::list< TypeDecl* > &decls ) {
@@ -271,9 +260,9 @@
 
 	/// Builds a layout function declaration
-	FunctionDecl *buildLayoutFunctionDecl( AggregateDecl *typeDecl, unsigned int functionNesting, FunctionType *layoutFnType ) {
+	FunctionDecl *buildLayoutFunctionDecl( AggregateDecl *typeDecl, bool isInFunction, FunctionType *layoutFnType ) {
 		// Routines at global scope marked "static" to prevent multiple definitions is separate translation units
 		// because each unit generates copies of the default routines for each aggregate.
 		FunctionDecl *layoutDecl = new FunctionDecl( layoutofName( typeDecl ),
-													 functionNesting > 0 ? Type::StorageClasses() : Type::StorageClasses( Type::Static ),
+													 isInFunction ? Type::StorageClasses() : Type::StorageClasses( Type::Static ),
 													 LinkageSpec::AutoGen, layoutFnType, new CompoundStmt(),
 													 std::list< Attribute * >(), Type::FuncSpecifiers( Type::Inline ) );
@@ -347,5 +336,5 @@
 
 		// build function decl
-		FunctionDecl *layoutDecl = buildLayoutFunctionDecl( structDecl, functionNesting, layoutFnType );
+		FunctionDecl *layoutDecl = buildLayoutFunctionDecl( structDecl, isInFunction(), layoutFnType );
 
 		// calculate struct layout in function body
@@ -401,5 +390,5 @@
 
 		// build function decl
-		FunctionDecl *layoutDecl = buildLayoutFunctionDecl( unionDecl, functionNesting, layoutFnType );
+		FunctionDecl *layoutDecl = buildLayoutFunctionDecl( unionDecl, isInFunction(), layoutFnType );
 
 		// calculate union layout in function body
