Index: src/SymTab/Indexer.cc
===================================================================
--- src/SymTab/Indexer.cc	(revision 0cb1d61bd1400ff6dd262a8ac61fc7d75dcf5f5c)
+++ src/SymTab/Indexer.cc	(revision 7d5e2436c32c5d15cb1fe90857b9c64fd226eb6b)
@@ -5,10 +5,10 @@
 // file "LICENCE" distributed with Cforall.
 //
-// Indexer.cc -- 
+// Indexer.cc --
 //
 // Author           : Richard C. Bilson
 // Created On       : Sun May 17 21:37:33 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Mar  2 17:31:29 2016
+// Last Modified By : Rob Schluntz
+// Last Modified On : Fri Apr 22 15:25:43 2016
 // Update Count     : 11
 //
@@ -59,5 +59,5 @@
 		}
 	}
-	
+
 	template< typename Decl >
 	void dump( const std::unordered_map< std::string, Decl* > &table, std::ostream &os ) {
@@ -66,5 +66,5 @@
 		} // for
 	}
-	
+
 	struct Indexer::Impl {
 		Impl( unsigned long _scope ) : refCount(1), scope( _scope ), size( 0 ), base(),
@@ -76,5 +76,5 @@
 		unsigned long size;       ///< Number of elements stored in this table
 		const Indexer base;       ///< Base indexer this extends
-		
+
 		IdTable idTable;          ///< Identifier namespace
 		TypeTable typeTable;      ///< Type namespace
@@ -213,14 +213,15 @@
 	void Indexer::visit( StructDecl *aggregateDecl ) {
 		// make up a forward declaration and add it before processing the members
-		StructDecl fwdDecl( aggregateDecl->get_name() );
+		// needs to be on the heap because addStruct saves the pointer
+		StructDecl &fwdDecl = *new StructDecl( aggregateDecl->get_name() );
 		cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() );
 		debugPrint( "Adding fwd decl for struct " << fwdDecl.get_name() << std::endl );
 		addStruct( &fwdDecl );
-  
+
 		enterScope();
 		acceptAll( aggregateDecl->get_parameters(), *this );
 		acceptAll( aggregateDecl->get_members(), *this );
 		leaveScope();
-  
+
 		debugPrint( "Adding struct " << aggregateDecl->get_name() << std::endl );
 		// this addition replaces the forward declaration
@@ -234,10 +235,10 @@
 		debugPrint( "Adding fwd decl for union " << fwdDecl.get_name() << std::endl );
 		addUnion( &fwdDecl );
-  
+
 		enterScope();
 		acceptAll( aggregateDecl->get_parameters(), *this );
 		acceptAll( aggregateDecl->get_members(), *this );
 		leaveScope();
-  
+
 		debugPrint( "Adding union " << aggregateDecl->get_name() << std::endl );
 		addUnion( aggregateDecl );
@@ -256,5 +257,5 @@
 		acceptAll( aggregateDecl->get_members(), *this );
 		leaveScope();
-  
+
 		debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl );
 		addTrait( aggregateDecl );
@@ -438,9 +439,9 @@
 	}
 
-	
+
 
 	void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const {
 		std::unordered_set< std::string > foundMangleNames;
-		
+
 		Indexer::Impl *searchTables = tables;
 		while ( searchTables ) {
@@ -452,9 +453,9 @@
 					// mark the mangled name as found, skipping this insertion if a declaration for that name has already been found
 					if ( foundMangleNames.insert( decl->first ).second == false ) continue;
-					
+
 					out.push_back( decl->second );
 				}
 			}
-			
+
 			// get declarations from base indexers
 			searchTables = searchTables->base.tables;
@@ -519,5 +520,5 @@
 			const MangleTable &mangleTable = decls->second;
 			for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) {
-				// check for C decls with the same name, skipping 
+				// check for C decls with the same name, skipping
 				// those with a compatible type (by mangleName)
 				if ( decl->second->get_linkage() == LinkageSpec::C && decl->first != mangleName ) return true;
@@ -527,5 +528,5 @@
 		return tables->base.hasIncompatibleCDecl( id, mangleName, scope );
 	}
-	
+
 	NamedTypeDecl *Indexer::lookupTypeAtScope( const std::string &id, unsigned long scope ) const {
 		if ( ! tables ) return 0;
@@ -535,5 +536,5 @@
 		return ret != tables->typeTable.end() ? ret->second : tables->base.lookupTypeAtScope( id, scope );
 	}
-	
+
 	StructDecl *Indexer::lookupStructAtScope( const std::string &id, unsigned long scope ) const {
 		if ( ! tables ) return 0;
@@ -543,5 +544,5 @@
 		return ret != tables->structTable.end() ? ret->second : tables->base.lookupStructAtScope( id, scope );
 	}
-	
+
 	EnumDecl *Indexer::lookupEnumAtScope( const std::string &id, unsigned long scope ) const {
 		if ( ! tables ) return 0;
@@ -551,5 +552,5 @@
 		return ret != tables->enumTable.end() ? ret->second : tables->base.lookupEnumAtScope( id, scope );
 	}
-	
+
 	UnionDecl *Indexer::lookupUnionAtScope( const std::string &id, unsigned long scope ) const {
 		if ( ! tables ) return 0;
@@ -559,5 +560,5 @@
 		return ret != tables->unionTable.end() ? ret->second : tables->base.lookupUnionAtScope( id, scope );
 	}
-	
+
 	TraitDecl *Indexer::lookupTraitAtScope( const std::string &id, unsigned long scope ) const {
 		if ( ! tables ) return 0;
@@ -602,5 +603,5 @@
 		return true;
 	}
-	
+
 	void Indexer::addId( DeclarationWithType *decl ) {
 		makeWritable();
@@ -621,10 +622,10 @@
 			if ( decl->get_linkage() == LinkageSpec::C && hasIncompatibleCDecl( name, mangleName, scope ) ) {
 				throw SemanticError( "invalid overload of C function ", decl );
-			} // NOTE this is broken in Richard's original code in such a way that it never triggers (it 
-			  // doesn't check decls that have the same manglename, and all C-linkage decls are defined to 
+			} // NOTE this is broken in Richard's original code in such a way that it never triggers (it
+			  // doesn't check decls that have the same manglename, and all C-linkage decls are defined to
 			  // have their name as their manglename, hence the error can never trigger).
-			  // The code here is closer to correct, but name mangling would have to be completely 
+			  // The code here is closer to correct, but name mangling would have to be completely
 			  // isomorphic to C type-compatibility, which it may not be.
-			
+
 			tables->idTable[ name ][ mangleName ] = decl;
 			++tables->size;
@@ -641,5 +642,5 @@
 		}
 	}
-	
+
 	void Indexer::addType( NamedTypeDecl *decl ) {
 		makeWritable();
@@ -672,5 +673,5 @@
 		addStruct( new StructDecl( id ) );
 	}
-	
+
 	void Indexer::addStruct( StructDecl *decl ) {
 		makeWritable();
@@ -690,5 +691,5 @@
 		}
 	}
-	
+
 	void Indexer::addEnum( EnumDecl *decl ) {
 		makeWritable();
@@ -712,5 +713,5 @@
 		addUnion( new UnionDecl( id ) );
 	}
-	
+
 	void Indexer::addUnion( UnionDecl *decl ) {
 		makeWritable();
@@ -730,5 +731,5 @@
 		}
 	}
-	
+
 	void Indexer::addTrait( TraitDecl *decl ) {
 		makeWritable();
@@ -751,5 +752,5 @@
 	void Indexer::enterScope() {
 		++scope;
-		
+
 		if ( doDebug ) {
 			std::cout << "--- Entering scope " << scope << std::endl;
@@ -804,5 +805,5 @@
 			os << "--- end ---" << std::endl;
 		}
-		
+
 	}
 } // namespace SymTab
