Index: src/InitTweak/FixGlobalInit.cc
===================================================================
--- src/InitTweak/FixGlobalInit.cc	(revision 711eee5ec8d25e9626c493d8242244335aa1f547)
+++ src/InitTweak/FixGlobalInit.cc	(revision 4e2461096b7c7d12f2ee84f0cef534e05aa25d48)
@@ -10,5 +10,5 @@
 // Created On       : Mon May 04 15:14:56 2016
 // Last Modified By : Rob Schluntz
-// Last Modified On : Wed May 04 16:53:12 2016
+// Last Modified On : Fri May 06 13:51:00 2016
 // Update Count     : 2
 //
@@ -30,11 +30,16 @@
 	class GlobalFixer : public Visitor {
 	  public:
-		GlobalFixer( const std::string & fileName );
+		GlobalFixer();
 
 		virtual void visit( ObjectDecl *objDecl );
 		virtual void visit( FunctionDecl *functionDecl );
+		virtual void visit( StructDecl *aggregateDecl );
+		virtual void visit( UnionDecl *aggregateDecl );
+		virtual void visit( EnumDecl *aggregateDecl );
+		virtual void visit( TraitDecl *aggregateDecl );
+		virtual void visit( TypeDecl *typeDecl );
 
 		UniqueName tempNamer;
-		FunctionDecl * initFunction;
+		CompoundStmt * block;
 	};
 
@@ -83,7 +88,14 @@
 
 	void fixGlobalInit( std::list< Declaration * > & translationUnit, const std::string & name ) {
-		GlobalFixer fixer( name );
+		GlobalFixer fixer;
 		acceptAll( translationUnit, fixer );
-		translationUnit.push_back( fixer.initFunction );
+		// attribute only appears on the forward declaration, so need to make two function decls:
+		// one with the body, one with the attribute.
+		FunctionDecl * initFunction = new FunctionDecl( initName( name ), DeclarationNode::NoStorageClass, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), 0, false, false );
+		FunctionDecl * forward = initFunction->clone();
+		forward->set_attribute( FunctionDecl::Constructor );
+		initFunction->set_statements( fixer.block );
+		translationUnit.push_back( forward );
+		translationUnit.push_back( initFunction );
 	}
 
@@ -97,13 +109,16 @@
   }
 
-	GlobalFixer::GlobalFixer( const std::string & fileName ) : tempNamer( "_global_init" ) {
-		initFunction = new FunctionDecl( initName( fileName ), DeclarationNode::NoStorageClass, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false );
+	GlobalFixer::GlobalFixer() : tempNamer( "_global_init" ), block( new CompoundStmt( noLabels ) ) {
 	}
 
 	void GlobalFixer::visit( ObjectDecl *objDecl ) {
-		std::list< Statement * > & statements = initFunction->get_statements()->get_kids();
+		std::list< Statement * > & statements = block->get_kids();
 
+		if ( objDecl->get_init() == NULL ) return;
+		if ( objDecl->get_type()->get_isConst() ) return; // temporary: can't assign to a const variable
 		// C allows you to initialize objects with constant expressions
-		if ( isConstExpr( objDecl->get_init() ) ) return;
+		// xxx - this is an optimization. Need to first resolve constructors before we decide
+		// to keep C-style initializer.
+		// if ( isConstExpr( objDecl->get_init() ) ) return;
 
 		// steal initializer from object and attach it to a new temporary
@@ -121,7 +136,12 @@
 	}
 
-	void GlobalFixer::visit( FunctionDecl *functionDecl ) {
-		// only modify global variables
-	}
+	// only modify global variables
+	void GlobalFixer::visit( FunctionDecl *functionDecl ) {}
+	void GlobalFixer::visit( StructDecl *aggregateDecl ) {}
+	void GlobalFixer::visit( UnionDecl *aggregateDecl ) {}
+	void GlobalFixer::visit( EnumDecl *aggregateDecl ) {}
+	void GlobalFixer::visit( TraitDecl *aggregateDecl ) {}
+	void GlobalFixer::visit( TypeDecl *typeDecl ) {}
+
 } // namespace InitTweak
 
