Index: src/SymTab/Autogen.h
===================================================================
--- src/SymTab/Autogen.h	(revision 39f84a4e271ab1b20b0bd4bae4f1ca69460c1dc7)
+++ src/SymTab/Autogen.h	(revision 8a443f46101a75053a6487d83a41a3085f490ef9)
@@ -37,9 +37,9 @@
 	/// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls.
 	template< typename OutputIterator >
-	void genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool forward = true );
+	void genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false, bool forward = true );
 
 	/// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Should only be called with non-array types.
 	template< typename OutputIterator >
-	void genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out ) {
+	void genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false ) {
 		// want to be able to generate assignment, ctor, and dtor generically,
 		// so fname is either ?=?, ?{}, or ^?{}
@@ -47,5 +47,19 @@
 
 		// do something special for unnamed members
-		fExpr->get_args().push_back( new AddressExpr( dstParam ) );
+		dstParam = new AddressExpr( dstParam );
+		if ( addCast ) {
+			// cast to T* with qualifiers removed, so that qualified objects can be constructed
+			// and destructed with the same functions as non-qualified objects.
+			// unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument
+			// must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever
+			// remove lvalue as a qualifier, this can change to
+			//   type->get_qualifiers() = Type::Qualifiers();
+			assert( type );
+			Type * castType = type->clone();
+			castType->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, true);
+			castType->set_isLvalue( true ); // xxx - might not need this
+			dstParam = new CastExpr( dstParam, new PointerType( Type::Qualifiers(), castType ) );
+		}
+		fExpr->get_args().push_back( dstParam );
 
     Statement * listInit = srcParam.buildListInit( fExpr );
@@ -56,12 +70,8 @@
     std::list< Expression * > args = *++srcParam;
     fExpr->get_args().splice( fExpr->get_args().end(), args );
-/*		if ( srcParam ) {
-			// xxx -
-			// make srcParam more complicated
-			// if srcParam contains
-			fExpr->get_args().push_back( srcParam );
-		}
-*/
+
 		*out++ = new ExprStmt( noLabels, fExpr );
+
+    srcParam.clearArrayIndices();
 	}
 
@@ -69,5 +79,5 @@
 	/// If forward is true, loop goes from 0 to N-1, else N-1 to 0
 	template< typename OutputIterator >
-	void genArrayCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, bool forward = true ) {
+	void genArrayCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, bool addCast = false, bool forward = true ) {
 		static UniqueName indexName( "_index" );
 
@@ -124,5 +134,5 @@
 		// for stmt's body, eventually containing call
 		CompoundStmt * body = new CompoundStmt( noLabels );
-		genCall( srcParam, dstParam, fname, back_inserter( body->get_kids() ), array->get_base(), forward );
+		genCall( srcParam, dstParam, fname, back_inserter( body->get_kids() ), array->get_base(), addCast, forward );
 
 		// block containing for stmt and index variable
@@ -136,9 +146,9 @@
 
 	template< typename OutputIterator >
-	void genCall( InitTweak::InitExpander &  srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool forward ) {
+	void genCall( InitTweak::InitExpander &  srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) {
 		if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) {
-			genArrayCall( srcParam, dstParam, fname, out, at, forward );
+			genArrayCall( srcParam, dstParam, fname, out, at, addCast, forward );
 		} else {
-			genScalarCall( srcParam, dstParam, fname, out );
+			genScalarCall( srcParam, dstParam, fname, out, type, addCast );
 		}
 	}
@@ -155,6 +165,7 @@
 		if ( isUnnamedBitfield( obj ) ) return;
 
+		bool addCast = (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && obj->get_bitfieldWidth() == NULL ) );
 		std::list< Statement * > stmts;
-		genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->get_type(), forward );
+		genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->get_type(), addCast, forward );
 
 		// currently genCall should produce at most one element, but if that changes then the next line needs to be updated to grab the statement which contains the call
@@ -162,5 +173,5 @@
     if ( stmts.size() == 1 ) {
   		Statement * callStmt = stmts.front();
-  		if ( (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && obj->get_bitfieldWidth() == NULL ) ) ) {
+  		if ( addCast ) {
   			// implicitly generated ctor/dtor calls should be wrapped
   			// so that later passes are aware they were generated.
