Index: src/AST/Pass.hpp
===================================================================
--- src/AST/Pass.hpp	(revision bfcd3af76db74e3dbbed12a62295035015729a46)
+++ src/AST/Pass.hpp	(revision 91b9e107eb969e2dfc95e1fae9cd3907d68c0774)
@@ -351,6 +351,6 @@
 	};
 
-	template< typename core_t>
-	friend auto __pass::at_cleanup( core_t & core, int ) -> decltype( &core.at_cleanup );
+	template< typename core_t >
+	friend auto __pass::make_value_guard( core_t & core, int ) -> decltype( value_guard( core.at_cleanup ) );
 public:
 
Index: src/AST/Pass.impl.hpp
===================================================================
--- src/AST/Pass.impl.hpp	(revision bfcd3af76db74e3dbbed12a62295035015729a46)
+++ src/AST/Pass.impl.hpp	(revision 91b9e107eb969e2dfc95e1fae9cd3907d68c0774)
@@ -27,9 +27,9 @@
 	using namespace ast; \
 	/* back-up the last known code location */ \
-	__attribute__((unused)) auto loc_guard = ast::__pass::make_location_guard( core, node, 0 ); \
+	__attribute__((unused)) auto guard0 = __pass::make_location_guard( core, node, 0 ); \
 	/* back-up the visit children */ \
-	__attribute__((unused)) ast::__pass::visit_children_guard guard1( ast::__pass::visit_children(core, 0) ); \
+	__attribute__((unused)) auto guard1 = __pass::make_visit_children_guard( core, 0 ); \
 	/* setup the scope for passes that want to run code at exit */ \
-	__attribute__((unused)) ast::__pass::guard_value          guard2( ast::__pass::at_cleanup    (core, 0) ); \
+	__attribute__((unused)) auto guard2 = __pass::make_value_guard( core, 0 ); \
 	/* begin tracing memory allocation if requested by this pass */ \
 	__pass::beginTrace( core, 0 ); \
Index: src/AST/Pass.proto.hpp
===================================================================
--- src/AST/Pass.proto.hpp	(revision bfcd3af76db74e3dbbed12a62295035015729a46)
+++ src/AST/Pass.proto.hpp	(revision 91b9e107eb969e2dfc95e1fae9cd3907d68c0774)
@@ -40,18 +40,19 @@
 typedef std::function<void( cleanup_func_t, void * )> at_cleanup_t;
 
-/// Implementation of the guard value
-/// Created inside the visit scope
-class guard_value {
+/// Replaces guards we don't want to use.
+struct empty_guard {
+};
+
+/// Implementation of the value guard. Created inside the visit scope.
+class value_guard {
 public:
 	/// Push onto the cleanup
-	guard_value( at_cleanup_t * at_cleanup ) {
-		if( at_cleanup ) {
-			*at_cleanup = [this]( cleanup_func_t && func, void* val ) {
-				push( std::move( func ), val );
-			};
-		}
-	}
-
-	~guard_value() {
+	value_guard( at_cleanup_t & at_cleanup ) {
+		at_cleanup = [this]( cleanup_func_t && func, void* val ) {
+			push( std::move( func ), val );
+		};
+	}
+
+	~value_guard() {
 		while( !cleanups.empty() ) {
 			auto& cleanup = cleanups.top();
@@ -74,23 +75,4 @@
 
 	std::stack< cleanup_t, std::vector<cleanup_t> > cleanups;
-};
-
-// Guard structure implementation for whether or not children should be visited
-class visit_children_guard {
-public:
-
-	visit_children_guard( bool * ref ) :
-		m_ref( ref ), m_val( true )
-	{
-		if ( m_ref ) { m_val = *m_ref; *m_ref = true; }
-	}
-
-	~visit_children_guard() {
-		if ( m_ref ) { *m_ref = m_val; }
-	}
-
-private:
-	bool * m_ref;
-	bool   m_val;
 };
 
@@ -280,5 +262,4 @@
 FIELD_PTR( declsToAddAfter , std::list< ast::ptr< ast::Decl > > )
 FIELD_PTR( visit_children, bool )
-FIELD_PTR( at_cleanup, __pass::at_cleanup_t )
 FIELD_PTR( visitor, ast::Pass<core_t> * const )
 FIELD_PTR( translationUnit, const TranslationUnit * )
@@ -314,6 +295,9 @@
 }
 
+// These are the guards declared at the beginning of a visit.
+// They are replaced with empty objects when not used.
+
 template< typename core_t, typename node_t >
-static auto make_location_guard( core_t & core, node_t * node, int )
+static inline auto make_location_guard( core_t & core, node_t * node, int )
 		-> decltype( node->location, ValueGuardPtr<const CodeLocation *>( &core.location ) ) {
 	ValueGuardPtr<const CodeLocation *> guard( &core.location );
@@ -323,6 +307,31 @@
 
 template< typename core_t, typename node_t >
-static auto make_location_guard( core_t &, node_t *, long ) -> int {
-	return 0;
+static inline empty_guard make_location_guard( core_t &, node_t *, long ) {
+	return empty_guard();
+}
+
+template< typename core_t >
+static inline auto make_visit_children_guard( core_t & core, int )
+		-> decltype( ValueGuardPtr<bool>( &core.visit_children ) ) {
+	ValueGuardPtr<bool> guard( &core.visit_children );
+	core.visit_children = true;
+	return guard;
+}
+
+template< typename core_t >
+static inline empty_guard make_visit_children_guard( core_t &, long ) {
+	return empty_guard();
+}
+
+template< typename core_t >
+static inline auto make_value_guard( core_t & core, int )
+		-> decltype( value_guard( core.at_cleanup ) ) {
+	// Requires guaranteed copy elision:
+	return value_guard( core.at_cleanup );
+}
+
+template< typename core_t >
+static inline empty_guard make_value_guard( core_t &, long ) {
+	return empty_guard();
 }
 
