Index: src/GenPoly/Box.cpp
===================================================================
--- src/GenPoly/Box.cpp	(revision 4dc3b8c90f62876e9e5e2b84283aebb28622582a)
+++ src/GenPoly/Box.cpp	(revision 2f8d351e0fb1ea4f22059f53d0f0f6ffe6e06908)
@@ -40,4 +40,15 @@
 namespace {
 
+/// The layout type is used to represent sizes, alignments and offsets.
+ast::BasicType * makeLayoutType() {
+	return new ast::BasicType( ast::BasicType::LongUnsignedInt );
+}
+
+/// Fixed version of layout type (just adding a 'C' in C++ style).
+ast::BasicType * makeLayoutCType() {
+	return new ast::BasicType( ast::BasicType::LongUnsignedInt,
+		ast::CV::Qualifiers( ast::CV::Const ) );
+}
+
 // --------------------------------------------------------------------------
 /// Adds layout-generation functions to polymorphic types.
@@ -60,8 +71,4 @@
 	}
 	return sizedParams;
-}
-
-ast::BasicType * makeSizeAlignType() {
-	return new ast::BasicType( ast::BasicType::LongUnsignedInt );
 }
 
@@ -76,16 +83,16 @@
 			sizedParam->location,
 			sizeofName( paramName ),
-			makeSizeAlignType()
+			makeLayoutCType()
 		) );
 		params.emplace_back( new ast::ObjectDecl(
 			sizedParam->location,
 			alignofName( paramName ),
-			makeSizeAlignType()
+			makeLayoutCType()
 		) );
 	}
 }
 
-ast::Type * makeSizeAlignOutType() {
-	return new ast::PointerType( makeSizeAlignType() );
+ast::Type * makeLayoutOutType() {
+	return new ast::PointerType( makeLayoutType() );
 }
 
@@ -104,10 +111,10 @@
 		location,
 		sizeofName( aggr->name ),
-		makeSizeAlignOutType()
+		makeLayoutOutType()
 	);
 	ast::ObjectDecl * alignParam = new ast::ObjectDecl(
 		location,
 		alignofName( aggr->name ),
-		makeSizeAlignOutType()
+		makeLayoutOutType()
 	);
 	ast::ObjectDecl * offsetParam = nullptr;
@@ -117,5 +124,5 @@
 			location,
 			offsetofName( aggr->name ),
-			makeSizeAlignOutType()
+			makeLayoutOutType()
 		);
 		params.push_back( offsetParam );
@@ -1372,11 +1379,20 @@
 };
 
-// size/align/offset parameters may not be used, so add the unused attribute.
 ast::ObjectDecl * makeObj(
 		CodeLocation const & location, std::string const & name ) {
+	// The size/align parameters may be unused, so add the unused attribute.
 	return new ast::ObjectDecl( location, name,
-		makeSizeAlignType(),
+		makeLayoutCType(),
 		nullptr, ast::Storage::Classes(), ast::Linkage::C, nullptr,
 		{ new ast::Attribute( "unused" ) } );
+}
+
+/// A modified and specialized version of ast::add_qualifiers.
+ast::Type const * addConst( ast::Type const * type ) {
+	ast::CV::Qualifiers cvq = { ast::CV::Const };
+	if ( ( type->qualifiers & cvq ) != 0 ) return type;
+	auto mutType = ast::mutate( type );
+	mutType->qualifiers |= cvq;
+	return mutType;
 }
 
@@ -1418,9 +1434,10 @@
 	}
 	for ( ast::ptr<ast::DeclWithType> & assert : mutDecl->assertions ) {
+		ast::DeclWithType * mutAssert = ast::mutate( assert.get() );
 		// Assertion parameters may not be used in body,
 		// pass along with unused attribute.
-		assert.get_and_mutate()->attributes.push_back(
-			new ast::Attribute( "unused" ) );
-		inferredParams.push_back( assert );
+		mutAssert->attributes.push_back( new ast::Attribute( "unused" ) );
+		mutAssert->set_type( addConst( mutAssert->get_type() ) );
+		inferredParams.emplace_back( mutAssert );
 	}
 	mutDecl->assertions.clear();
@@ -1609,5 +1626,5 @@
 
 /// Converts polymorphic type into a suitable monomorphic representation.
-/// Currently: __attribute__((aligned(8) )) char[size_T];
+/// Currently: __attribute__(( aligned(8) )) char[size_T];
 ast::Type * polyToMonoType( CodeLocation const & location,
 		ast::Type const * declType ) {
@@ -1615,9 +1632,8 @@
 	auto size = new ast::NameExpr( location,
 		sizeofName( Mangle::mangleType( declType ) ) );
-	auto aligned = new ast::Attribute( "aligned",
-		{ ast::ConstantExpr::from_int( location, 8 ) } );
 	auto ret = new ast::ArrayType( charType, size,
 		ast::VariableLen, ast::DynamicDim, ast::CV::Qualifiers() );
-	ret->attributes.push_back( aligned );
+	ret->attributes.emplace_back( new ast::Attribute( "aligned",
+		{ ast::ConstantExpr::from_int( location, 8 ) } ) );
 	return ret;
 }
@@ -1645,9 +1661,7 @@
 	ast::TypeInstType inst( decl->name, decl );
 	std::string typeName = Mangle::mangleType( &inst );
-	ast::Type * layoutType = new ast::BasicType(
-		ast::BasicType::LongUnsignedInt );
 
 	ast::ObjectDecl * sizeDecl = new ast::ObjectDecl( decl->location,
-		sizeofName( typeName ), layoutType,
+		sizeofName( typeName ), makeLayoutCType(),
 		new ast::SingleInit( decl->location,
 			new ast::SizeofExpr( decl->location, deepCopy( base ) )
@@ -1655,5 +1669,5 @@
 	);
 	ast::ObjectDecl * alignDecl = new ast::ObjectDecl( decl->location,
-		alignofName( typeName ), layoutType,
+		alignofName( typeName ), makeLayoutCType(),
 		new ast::SingleInit( decl->location,
 			new ast::AlignofExpr( decl->location, deepCopy( base ) )
@@ -1752,7 +1766,7 @@
 long findMember( ast::DeclWithType const * memberDecl,
 		const ast::vector<ast::Decl> & baseDecls ) {
-	for ( auto pair : enumerate( baseDecls ) ) {
-		if ( isMember( memberDecl, pair.val.get() ) ) {
-			return pair.idx;
+	for ( auto const & [index, value] : enumerate( baseDecls ) ) {
+		if ( isMember( memberDecl, value.get() ) ) {
+			return index;
 		}
 	}
@@ -1912,11 +1926,7 @@
 	knownOffsets.insert( offsetName );
 
-	auto baseMembers = type->base->members;
-	ast::Type const * offsetType = new ast::BasicType(
-		ast::BasicType::LongUnsignedInt );
-
 	// Build initializer list for offset array.
 	ast::vector<ast::Init> inits;
-	for ( ast::ptr<ast::Decl> & member : baseMembers ) {
+	for ( ast::ptr<ast::Decl> const & member : type->base->members ) {
 		auto memberDecl = member.as<ast::DeclWithType>();
 		assertf( memberDecl, "Requesting offset of non-DWT member: %s",
@@ -1932,6 +1942,6 @@
 	auto offsetArray = makeVar( expr->location, offsetName,
 		new ast::ArrayType(
-			offsetType,
-			ast::ConstantExpr::from_ulong( expr->location, baseMembers.size() ),
+			makeLayoutType(),
+			ast::ConstantExpr::from_ulong( expr->location, inits.size() ),
 			ast::FixedLen,
 			ast::DynamicDim
@@ -2012,5 +2022,4 @@
 		// parameters to the layout call.
 		knownLayouts.insert( typeName );
-		ast::Type const * layoutType = makeSizeAlignType();
 
 		int memberCount = inst->base->members.size();
@@ -2018,9 +2027,9 @@
 			// All empty structures have the same layout (size 1, align 1).
 			makeVar( location,
-				sizeofName( typeName ), layoutType,
+				sizeofName( typeName ), makeLayoutType(),
 				new ast::SingleInit( location,
 						ast::ConstantExpr::from_ulong( location, 1 ) ) );
 			makeVar( location,
-				alignofName( typeName ), ast::deepCopy( layoutType ),
+				alignofName( typeName ), makeLayoutType(),
 				new ast::SingleInit( location,
 						ast::ConstantExpr::from_ulong( location, 1 ) ) );
@@ -2028,11 +2037,11 @@
 		} else {
 			ast::ObjectDecl const * sizeofVar = makeVar( location,
-				sizeofName( typeName ), deepCopy( layoutType ), nullptr );
+				sizeofName( typeName ), makeLayoutType(), nullptr );
 			ast::ObjectDecl const * alignofVar = makeVar( location,
-				alignofName( typeName ), deepCopy( layoutType ), nullptr );
+				alignofName( typeName ), makeLayoutType(), nullptr );
 			ast::ObjectDecl const * offsetofVar = makeVar( location,
 				offsetofName( typeName ),
 				new ast::ArrayType(
-					layoutType,
+					makeLayoutType(),
 					ast::ConstantExpr::from_int( location, memberCount ),
 					ast::FixedLen,
@@ -2078,10 +2087,9 @@
 		// parameters to the layout call.
 		knownLayouts.insert( typeName );
-		ast::Type const * layoutType = makeSizeAlignType();
 
 		ast::ObjectDecl * sizeofVar = makeVar( location,
-			sizeofName( typeName ), layoutType );
+			sizeofName( typeName ), makeLayoutType() );
 		ast::ObjectDecl * alignofVar = makeVar( location,
-			alignofName( typeName ), ast::deepCopy( layoutType ) );
+			alignofName( typeName ), makeLayoutType() );
 
 		ast::UntypedExpr * layoutCall = new ast::UntypedExpr( location,
Index: tests/.expect/functions.arm64.txt
===================================================================
--- tests/.expect/functions.arm64.txt	(revision 4dc3b8c90f62876e9e5e2b84283aebb28622582a)
+++ tests/.expect/functions.arm64.txt	(revision 2f8d351e0fb1ea4f22059f53d0f0f6ffe6e06908)
@@ -105,5 +105,5 @@
 struct _tuple2_ {
 };
-static inline void _layoutof__tuple2_(unsigned long int *_sizeof__tuple2_, unsigned long int *_alignof__tuple2_, unsigned long int *_offsetof__tuple2_, unsigned long int _sizeof_Y15tuple_param_2_0, unsigned long int _alignof_Y15tuple_param_2_0, unsigned long int _sizeof_Y15tuple_param_2_1, unsigned long int _alignof_Y15tuple_param_2_1){
+static inline void _layoutof__tuple2_(unsigned long int *_sizeof__tuple2_, unsigned long int *_alignof__tuple2_, unsigned long int *_offsetof__tuple2_, const unsigned long int _sizeof_Y15tuple_param_2_0, const unsigned long int _alignof_Y15tuple_param_2_0, const unsigned long int _sizeof_Y15tuple_param_2_1, const unsigned long int _alignof_Y15tuple_param_2_1){
     ((void)((*_sizeof__tuple2_)=0));
     ((void)((*_alignof__tuple2_)=1));
@@ -136,5 +136,5 @@
 struct _tuple3_ {
 };
-static inline void _layoutof__tuple3_(unsigned long int *_sizeof__tuple3_, unsigned long int *_alignof__tuple3_, unsigned long int *_offsetof__tuple3_, unsigned long int _sizeof_Y15tuple_param_3_0, unsigned long int _alignof_Y15tuple_param_3_0, unsigned long int _sizeof_Y15tuple_param_3_1, unsigned long int _alignof_Y15tuple_param_3_1, unsigned long int _sizeof_Y15tuple_param_3_2, unsigned long int _alignof_Y15tuple_param_3_2){
+static inline void _layoutof__tuple3_(unsigned long int *_sizeof__tuple3_, unsigned long int *_alignof__tuple3_, unsigned long int *_offsetof__tuple3_, const unsigned long int _sizeof_Y15tuple_param_3_0, const unsigned long int _alignof_Y15tuple_param_3_0, const unsigned long int _sizeof_Y15tuple_param_3_1, const unsigned long int _alignof_Y15tuple_param_3_1, const unsigned long int _sizeof_Y15tuple_param_3_2, const unsigned long int _alignof_Y15tuple_param_3_2){
     ((void)((*_sizeof__tuple3_)=0));
     ((void)((*_alignof__tuple3_)=1));
Index: tests/.expect/functions.x64.txt
===================================================================
--- tests/.expect/functions.x64.txt	(revision 4dc3b8c90f62876e9e5e2b84283aebb28622582a)
+++ tests/.expect/functions.x64.txt	(revision 2f8d351e0fb1ea4f22059f53d0f0f6ffe6e06908)
@@ -105,5 +105,5 @@
 struct _tuple2_ {
 };
-static inline void _layoutof__tuple2_(unsigned long int *_sizeof__tuple2_, unsigned long int *_alignof__tuple2_, unsigned long int *_offsetof__tuple2_, unsigned long int _sizeof_Y15tuple_param_2_0, unsigned long int _alignof_Y15tuple_param_2_0, unsigned long int _sizeof_Y15tuple_param_2_1, unsigned long int _alignof_Y15tuple_param_2_1){
+static inline void _layoutof__tuple2_(unsigned long int *_sizeof__tuple2_, unsigned long int *_alignof__tuple2_, unsigned long int *_offsetof__tuple2_, const unsigned long int _sizeof_Y15tuple_param_2_0, const unsigned long int _alignof_Y15tuple_param_2_0, const unsigned long int _sizeof_Y15tuple_param_2_1, const unsigned long int _alignof_Y15tuple_param_2_1){
     ((void)((*_sizeof__tuple2_)=0));
     ((void)((*_alignof__tuple2_)=1));
@@ -136,5 +136,5 @@
 struct _tuple3_ {
 };
-static inline void _layoutof__tuple3_(unsigned long int *_sizeof__tuple3_, unsigned long int *_alignof__tuple3_, unsigned long int *_offsetof__tuple3_, unsigned long int _sizeof_Y15tuple_param_3_0, unsigned long int _alignof_Y15tuple_param_3_0, unsigned long int _sizeof_Y15tuple_param_3_1, unsigned long int _alignof_Y15tuple_param_3_1, unsigned long int _sizeof_Y15tuple_param_3_2, unsigned long int _alignof_Y15tuple_param_3_2){
+static inline void _layoutof__tuple3_(unsigned long int *_sizeof__tuple3_, unsigned long int *_alignof__tuple3_, unsigned long int *_offsetof__tuple3_, const unsigned long int _sizeof_Y15tuple_param_3_0, const unsigned long int _alignof_Y15tuple_param_3_0, const unsigned long int _sizeof_Y15tuple_param_3_1, const unsigned long int _alignof_Y15tuple_param_3_1, const unsigned long int _sizeof_Y15tuple_param_3_2, const unsigned long int _alignof_Y15tuple_param_3_2){
     ((void)((*_sizeof__tuple3_)=0));
     ((void)((*_alignof__tuple3_)=1));
Index: tests/.expect/functions.x86.txt
===================================================================
--- tests/.expect/functions.x86.txt	(revision 4dc3b8c90f62876e9e5e2b84283aebb28622582a)
+++ tests/.expect/functions.x86.txt	(revision 2f8d351e0fb1ea4f22059f53d0f0f6ffe6e06908)
@@ -105,5 +105,5 @@
 struct _tuple2_ {
 };
-static inline void _layoutof__tuple2_(unsigned long int *_sizeof__tuple2_, unsigned long int *_alignof__tuple2_, unsigned long int *_offsetof__tuple2_, unsigned long int _sizeof_Y15tuple_param_2_0, unsigned long int _alignof_Y15tuple_param_2_0, unsigned long int _sizeof_Y15tuple_param_2_1, unsigned long int _alignof_Y15tuple_param_2_1){
+static inline void _layoutof__tuple2_(unsigned long int *_sizeof__tuple2_, unsigned long int *_alignof__tuple2_, unsigned long int *_offsetof__tuple2_, const unsigned long int _sizeof_Y15tuple_param_2_0, const unsigned long int _alignof_Y15tuple_param_2_0, const unsigned long int _sizeof_Y15tuple_param_2_1, const unsigned long int _alignof_Y15tuple_param_2_1){
     ((void)((*_sizeof__tuple2_)=0));
     ((void)((*_alignof__tuple2_)=1));
@@ -136,5 +136,5 @@
 struct _tuple3_ {
 };
-static inline void _layoutof__tuple3_(unsigned long int *_sizeof__tuple3_, unsigned long int *_alignof__tuple3_, unsigned long int *_offsetof__tuple3_, unsigned long int _sizeof_Y15tuple_param_3_0, unsigned long int _alignof_Y15tuple_param_3_0, unsigned long int _sizeof_Y15tuple_param_3_1, unsigned long int _alignof_Y15tuple_param_3_1, unsigned long int _sizeof_Y15tuple_param_3_2, unsigned long int _alignof_Y15tuple_param_3_2){
+static inline void _layoutof__tuple3_(unsigned long int *_sizeof__tuple3_, unsigned long int *_alignof__tuple3_, unsigned long int *_offsetof__tuple3_, const unsigned long int _sizeof_Y15tuple_param_3_0, const unsigned long int _alignof_Y15tuple_param_3_0, const unsigned long int _sizeof_Y15tuple_param_3_1, const unsigned long int _alignof_Y15tuple_param_3_1, const unsigned long int _sizeof_Y15tuple_param_3_2, const unsigned long int _alignof_Y15tuple_param_3_2){
     ((void)((*_sizeof__tuple3_)=0));
     ((void)((*_alignof__tuple3_)=1));
