Index: src/Common/PassVisitor.h
===================================================================
--- src/Common/PassVisitor.h	(revision 1febef62b1cc0a533c2408d031d09dadd2c16fd4)
+++ src/Common/PassVisitor.h	(revision 02fdb8eb4c22b14a7fc7116a96f53d73dae71205)
@@ -4,4 +4,5 @@
 
 #include <stack>
+#include <type_traits>
 
 #include "Common/Stats.h"
@@ -301,5 +302,5 @@
 
 
-	TypeSubstitution ** 		get_env_ptr    () { return env_impl             ( pass, 0); }
+	auto			 		get_env_ptr    () -> decltype(env_impl( pass, 0)) { return env_impl( pass, 0); }
 	std::list< Statement* > * 	get_beforeStmts() { return stmtsToAddBefore_impl( pass, 0); }
 	std::list< Statement* > * 	get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); }
@@ -348,4 +349,13 @@
 };
 
+class WithConstTypeSubstitution {
+protected:
+	WithConstTypeSubstitution() = default;
+	~WithConstTypeSubstitution() = default;
+
+public:
+	const TypeSubstitution * env = nullptr;
+};
+
 class WithStmtsToAdd {
 protected:
Index: src/Common/PassVisitor.impl.h
===================================================================
--- src/Common/PassVisitor.impl.h	(revision 1febef62b1cc0a533c2408d031d09dadd2c16fd4)
+++ src/Common/PassVisitor.impl.h	(revision 02fdb8eb4c22b14a7fc7116a96f53d73dae71205)
@@ -253,5 +253,5 @@
 
 	// don't want statements from outer CompoundStmts to be added to this CompoundStmt
-	ValueGuardPtr< TypeSubstitution * >  oldEnv        ( get_env_ptr    () );
+	ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type >  oldEnv( get_env_ptr() );
 	ValueGuardPtr< DeclList_t >          oldBeforeDecls( get_beforeDecls() );
 	ValueGuardPtr< DeclList_t >          oldAfterDecls ( get_afterDecls () );
@@ -1995,5 +1995,5 @@
 
 	// don't want statements from outer CompoundStmts to be added to this StmtExpr
-	ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
+	ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type >  oldEnv( get_env_ptr() );
 	ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
 	ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
@@ -2012,5 +2012,5 @@
 
 	// don't want statements from outer CompoundStmts to be added to this StmtExpr
-	ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
+	ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type >  oldEnv( get_env_ptr() );
 	ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
 	ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
Index: src/Common/PassVisitor.proto.h
===================================================================
--- src/Common/PassVisitor.proto.h	(revision 1febef62b1cc0a533c2408d031d09dadd2c16fd4)
+++ src/Common/PassVisitor.proto.h	(revision 02fdb8eb4c22b14a7fc7116a96f53d73dae71205)
@@ -165,5 +165,5 @@
 static inline type * name##_impl( __attribute__((unused)) pass_type& pass, __attribute__((unused)) long unused ) { return nullptr;}    \
 
-FIELD_PTR( TypeSubstitution *, env )
+FIELD_PTR( const TypeSubstitution *, env )
 FIELD_PTR( std::list< Statement* >, stmtsToAddBefore )
 FIELD_PTR( std::list< Statement* >, stmtsToAddAfter  )
