Index: src/AST/Convert.cpp
===================================================================
--- src/AST/Convert.cpp	(revision 76ed81f81d14c3e5db5597f0020c3ea79b4b7b8c)
+++ src/AST/Convert.cpp	(revision 893e10686109623f2ba6a53bfd3f6918d203f977)
@@ -1342,10 +1342,9 @@
 };
 
-std::list< Declaration * > convert( std::list< ast::ptr< ast::Decl > > && translationUnit ) {
+std::list< Declaration * > convert( const std::list< ast::ptr< ast::Decl > > && translationUnit ) {
 	ConverterNewToOld c;
 	std::list< Declaration * > decls;
 	for(auto d : translationUnit) {
 		decls.emplace_back( c.decl( d ) );
-		delete d;
 	}
 	return decls;
@@ -1436,4 +1435,5 @@
 			{ old->get_funcSpec().val }
 		);
+		cache.emplace( old, decl );
 		decl->scopeLevel = old->scopeLevel;
 		decl->mangleName = old->mangleName;
@@ -1441,5 +1441,4 @@
 		decl->uniqueId   = old->uniqueId;
 		decl->extension  = old->extension;
-		cache.emplace( old, decl );
 
 		this->node = decl;
@@ -1458,4 +1457,5 @@
 			{ old->get_funcSpec().val }
 		};
+		cache.emplace( old, decl );
 		decl->scopeLevel = old->scopeLevel;
 		decl->mangleName = old->mangleName;
@@ -1463,5 +1463,4 @@
 		decl->uniqueId   = old->uniqueId;
 		decl->extension  = old->extension;
-		cache.emplace( old, decl );
 
 		this->node = decl;
@@ -1477,4 +1476,5 @@
 			{ old->linkage.val }
 		);
+		cache.emplace( old, decl );
 		decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
 		decl->body   = old->body;
@@ -1484,5 +1484,4 @@
 		decl->uniqueId   = old->uniqueId;
 		decl->storage    = { old->storageClasses.val };
-		cache.emplace( old, decl );
 
 		this->node = decl;
@@ -1497,4 +1496,5 @@
 			{ old->linkage.val }
 		);
+		cache.emplace( old, decl );
 		decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
 		decl->body   = old->body;
@@ -1504,5 +1504,4 @@
 		decl->uniqueId   = old->uniqueId;
 		decl->storage    = { old->storageClasses.val };
-		cache.emplace( old, decl );
 
 		this->node = decl;
@@ -1517,4 +1516,5 @@
 			{ old->linkage.val }
 		);
+		cache.emplace( old, decl );
 		decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
 		decl->body   = old->body;
@@ -1524,5 +1524,4 @@
 		decl->uniqueId   = old->uniqueId;
 		decl->storage    = { old->storageClasses.val };
-		cache.emplace( old, decl );
 
 		this->node = decl;
@@ -1537,4 +1536,5 @@
 			{ old->linkage.val }
 		);
+		cache.emplace( old, decl );
 		decl->parent = GET_ACCEPT_1(parent, AggregateDecl);
 		decl->body   = old->body;
@@ -1544,5 +1544,4 @@
 		decl->uniqueId   = old->uniqueId;
 		decl->storage    = { old->storageClasses.val };
-		cache.emplace( old, decl );
 
 		this->node = decl;
@@ -1560,9 +1559,9 @@
 			GET_ACCEPT_1(init, Type)
 		};
+		cache.emplace( old, decl );
 		decl->assertions = GET_ACCEPT_V(assertions, DeclWithType);
 		decl->params     = GET_ACCEPT_V(parameters, TypeDecl);
 		decl->extension  = old->extension;
 		decl->uniqueId   = old->uniqueId;
-		cache.emplace( old, decl );
 
 		this->node = decl;
@@ -1912,4 +1911,6 @@
 	ast::TypeSubstitution * convertTypeSubstitution(const TypeSubstitution * old) {
 
+		if (!old) return nullptr;
+
 		ast::TypeSubstitution *rslt = new ast::TypeSubstitution();
 
@@ -2703,6 +2704,6 @@
 		d->accept( c );
 		decls.emplace_back( c.decl() );
-		delete d;
-	}
+	}
+	deleteAll(translationUnit);
 	return decls;
 }
Index: src/AST/Expr.cpp
===================================================================
--- src/AST/Expr.cpp	(revision 76ed81f81d14c3e5db5597f0020c3ea79b4b7b8c)
+++ src/AST/Expr.cpp	(revision 893e10686109623f2ba6a53bfd3f6918d203f977)
@@ -159,4 +159,5 @@
 	assert( aggregate->result );
 
+<<<<<<< HEAD
 	// #warning Needs GenericSubsitution.cpp building to work correctly
 	// result.set_and_mutate( mem->get_type() )->qualifiers |= aggregate->result->qualifiers | CV::Lvalue;  // FIXME temporary patch
@@ -168,4 +169,7 @@
 	// ensure lvalue and appropriate restrictions from aggregate type
 	result.get_and_mutate()->qualifiers |= aggregate->result->qualifiers | CV::Lvalue;
+=======
+//	assert(!"unimplemented; need TypeSubstitution, genericSubstitution");
+>>>>>>> ef5ef56042ce2b547da955746d9986e26cf628ca
 }
 
Index: src/AST/Node.hpp
===================================================================
--- src/AST/Node.hpp	(revision 76ed81f81d14c3e5db5597f0020c3ea79b4b7b8c)
+++ src/AST/Node.hpp	(revision 893e10686109623f2ba6a53bfd3f6918d203f977)
@@ -121,5 +121,5 @@
 	template<typename o_node_t>
 	ptr_base & operator=( const o_node_t * node ) {
-		assign(strict_dynamic_cast<const node_t *>(node));
+		assign( node ? strict_dynamic_cast<const node_t *>(node) : nullptr );
 		return *this;
 	}
Index: src/AST/Pass.proto.hpp
===================================================================
--- src/AST/Pass.proto.hpp	(revision 76ed81f81d14c3e5db5597f0020c3ea79b4b7b8c)
+++ src/AST/Pass.proto.hpp	(revision 893e10686109623f2ba6a53bfd3f6918d203f977)
@@ -107,4 +107,12 @@
 		bool     * m_prev;
 		bool_ref * m_ref;
+	};
+
+	template<typename pass_t, typename node_t>
+	struct is_valid_previsit {
+		using ret_t = decltype( ((pass_t*)nullptr)->previsit( (const node_t *)nullptr ) );
+
+		static constexpr bool value = std::is_void< ret_t >::value ||
+			std::is_base_of<const node_t, typename std::remove_pointer<ret_t>::type >::value;
 	};
 
@@ -127,9 +135,13 @@
 	static inline auto previsit( pass_t & pass, const node_t * & node, int ) -> decltype( pass.previsit( node ), void() ) {
 		static_assert(
-			std::is_base_of<const node_t, typename std::remove_pointer<decltype( pass.previsit( node ) )>::type >::value,
-			"Previsit may not change the type of the node. Use postvisit instead."
+			is_valid_previsit<pass_t, node_t>::value,
+			"Previsit may not change the type of the node. It must return its paremeter or void."
 		);
-		node = pass.previsit( node );
-		assert(node);
+		if(std::is_void< decltype( pass.previsit(node) ) >::value) {
+			pass.previsit( node );
+		} else {
+			node = pass.previsit( node );
+			assert(node);
+		}
 	}
 
@@ -139,5 +151,7 @@
 	// PostVisit : never mutates the passed pointer but may return a different node
 	template<typename pass_t, typename node_t>
-	static inline auto postvisit( pass_t & pass, const node_t * node, int ) -> decltype( pass.postvisit( node ), (const node_t *)nullptr ) {
+	static inline auto postvisit( pass_t & pass, const node_t * node, int ) ->
+		decltype( pass.postvisit( node ), node->accept( *(Visitor*)nullptr ) )
+	{
 		return pass.postvisit( node );
 	}
Index: src/Common/utility.h
===================================================================
--- src/Common/utility.h	(revision 76ed81f81d14c3e5db5597f0020c3ea79b4b7b8c)
+++ src/Common/utility.h	(revision 893e10686109623f2ba6a53bfd3f6918d203f977)
@@ -74,7 +74,7 @@
 
 template< typename Container >
-void deleteAll( Container &container ) {
-	for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
-		delete *i;
+void deleteAll( const Container &container ) {
+	for ( const auto &i : container ) {
+		delete i;
 	} // for
 }
Index: src/include/cassert
===================================================================
--- src/include/cassert	(revision 76ed81f81d14c3e5db5597f0020c3ea79b4b7b8c)
+++ src/include/cassert	(revision 893e10686109623f2ba6a53bfd3f6918d203f977)
@@ -44,5 +44,6 @@
 
 template<typename T, typename U>
-static inline T strict_dynamic_cast( const U & src ) {
+static inline __attribute__((nonnull)) T strict_dynamic_cast( const U & src ) {
+	assert(src);
 	T ret = dynamic_cast<T>(src);
 	assertf(ret, "%s", toString(src).c_str());
