Index: src/Parser/TypedefTable.cc
===================================================================
--- src/Parser/TypedefTable.cc	(revision 3d26610b1bab2688ae61b5b0e34f63763ec3a35b)
+++ src/Parser/TypedefTable.cc	(revision ecae5860965de56ce3fadb77f1a7686686e37c67)
@@ -10,6 +10,6 @@
 // Created On       : Sat May 16 15:20:13 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Wed May 30 18:04:38 2018
-// Update Count     : 148
+// Last Modified On : Fri Jun  1 16:54:18 2018
+// Update Count     : 155
 //
 
@@ -54,19 +54,19 @@
 void TypedefTable::makeTypedef( const string & name ) {
 	if ( ! typedefTable.exists( name ) ) {
-		typedefTable.addToEnclosingScope( name, TYPEDEFname /*, "MTD"*/ );
+		typedefTable.addToEnclosingScope( name, TYPEDEFname, "MTD" );
 	} // if
 } // TypedefTable::makeTypedef
 
-void TypedefTable::addToScope( const std::string & identifier, int kind /*, const char * locn*/ ) {
+void TypedefTable::addToScope( const std::string & identifier, int kind, const char * locn __attribute__((unused)) ) {
 	auto scope = kindTable.currentScope();
-	debugPrint( cerr << "Adding at " /* << locn */ << " " << identifier << " as kind " << kind << " scope " << scope << endl );
+	debugPrint( cerr << "Adding at " << locn << " " << identifier << " as kind " << kind << " scope " << scope << endl );
 	auto ret = kindTable.insertAt( scope, identifier, kind );
 	if ( ! ret.second ) ret.first->second = kind;		// exists => update
 } // TypedefTable::addToScope
 
-void TypedefTable::addToEnclosingScope( const std::string & identifier, int kind /*, const char * locn*/ ) {
+void TypedefTable::addToEnclosingScope( const std::string & identifier, int kind, const char * locn __attribute__((unused)) ) {
 	assert( kindTable.currentScope() >= 1 );
 	auto scope = kindTable.currentScope() - 1;
-	debugPrint( cerr << "Adding2 at " /* << locn */ << " " << identifier << " as kind " << kind << " scope " << scope << endl );
+	debugPrint( cerr << "Adding+1 at " << locn << " " << identifier << " as kind " << kind << " scope " << scope << endl );
 	auto ret = kindTable.insertAt( scope, identifier, kind );
 	if ( ! ret.second ) ret.first->second = kind;		// exists => update
Index: src/Parser/TypedefTable.h
===================================================================
--- src/Parser/TypedefTable.h	(revision 3d26610b1bab2688ae61b5b0e34f63763ec3a35b)
+++ src/Parser/TypedefTable.h	(revision ecae5860965de56ce3fadb77f1a7686686e37c67)
@@ -10,6 +10,6 @@
 // Created On       : Sat May 16 15:24:36 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Wed May 30 17:02:49 2018
-// Update Count     : 82
+// Last Modified On : Thu May 31 23:23:47 2018
+// Update Count     : 83
 //
 
@@ -32,6 +32,6 @@
 	void changeKind( const std::string & identifier, int kind );
 	void makeTypedef( const std::string & name );
-	void addToScope( const std::string & identifier, int kind /*, const char **/ );
-	void addToEnclosingScope( const std::string & identifier, int kind /*, const char */ );
+	void addToScope( const std::string & identifier, int kind, const char * );
+	void addToEnclosingScope( const std::string & identifier, int kind, const char * );
 
 	void enterScope();
Index: src/Parser/parser.yy
===================================================================
--- src/Parser/parser.yy	(revision 3d26610b1bab2688ae61b5b0e34f63763ec3a35b)
+++ src/Parser/parser.yy	(revision ecae5860965de56ce3fadb77f1a7686686e37c67)
@@ -10,6 +10,6 @@
 // Created On       : Sat Sep  1 20:22:55 2001
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Thu May 31 15:11:40 2018
-// Update Count     : 3444
+// Last Modified On : Fri Jun  1 17:59:57 2018
+// Update Count     : 3476
 //
 
@@ -304,5 +304,5 @@
 %type<en> enumerator_value_opt
 
-%type<decl> exception_declaration external_definition external_definition_list external_definition_list_opt
+%type<decl> exception_declaration external_definition external_definition_list external_definition_list_no_pop_push external_definition_list_opt
 
 %type<decl> field_declaration field_declaration_list_opt field_declarator_opt field_declaring_list
@@ -644,5 +644,4 @@
 		// semantics checks, e.g., ++3, 3--, *3, &&3
 	| constant
-		{ $$ = $1; }
 	| string_literal
 		{ $$ = new ExpressionNode( $1 ); }
@@ -988,5 +987,4 @@
 		{ $$ = new StatementNode( build_if( $3, $5, $7 ) ); }
 	;
-
 
 if_control_expression:
@@ -1383,5 +1381,4 @@
 cfa_function_declaration:								// CFA
 	cfa_function_specifier
-		{ $$ = $1; }
 	| type_qualifier_list cfa_function_specifier
 		{ $$ = $2->addQualifiers( $1 ); }
@@ -1440,15 +1437,15 @@
 	TYPEDEF cfa_variable_specifier
 		{
-			typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "1"*/ );
+			typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname, "1" );
 			$$ = $2->addTypedef();
 		}
 	| TYPEDEF cfa_function_specifier
 		{
-			typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "2"*/ );
+			typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname, "2" );
 			$$ = $2->addTypedef();
 		}
 	| cfa_typedef_declaration pop ',' push no_attr_identifier
 		{
-			typedefTable.addToEnclosingScope( *$5, TYPEDEFname /*, "3"*/ );
+			typedefTable.addToEnclosingScope( *$5, TYPEDEFname, "3" );
 			$$ = $1->appendList( $1->cloneType( $5 ) );
 		}
@@ -1461,25 +1458,25 @@
 	TYPEDEF type_specifier declarator
 		{
-			typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "4"*/ );
+			typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "4" );
 			$$ = $3->addType( $2 )->addTypedef();
 		}
 	| typedef_declaration pop ',' push declarator
 		{
-			typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname /*, "5"*/ );
+			typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname, "5" );
 			$$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() );
 		}
 	| type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 )
 		{
-			typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "6"*/ );
+			typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "6" );
 			$$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef();
 		}
 	| type_specifier TYPEDEF declarator
 		{
-			typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "7"*/ );
+			typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "7" );
 			$$ = $3->addType( $1 )->addTypedef();
 		}
 	| type_specifier TYPEDEF type_qualifier_list declarator
 		{
-			typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "8"*/ );
+			typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "8" );
 			$$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 );
 		}
@@ -1937,5 +1934,4 @@
 		{ $$ = nullptr; }
 	| bit_subrange_size
-		{ $$ = $1; }
 	;
 
@@ -2187,5 +2183,4 @@
 type_parameter_list:									// CFA
 	type_parameter
-		{ $$ = $1; }
 	| type_parameter_list ',' type_parameter
 		{ $$ = $1->appendList( $3 ); }
@@ -2201,5 +2196,5 @@
 type_parameter:											// CFA
 	type_class no_attr_identifier_or_type_name
-		{ typedefTable.addToScope( *$2, TYPEDEFname /*, "9"*/ ); }
+		{ typedefTable.addToScope( *$2, TYPEDEFname, "9" ); }
 	  type_initializer_opt assertion_list_opt
 		{ $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); }
@@ -2270,10 +2265,10 @@
 	no_attr_identifier_or_type_name
 		{
-			typedefTable.addToEnclosingScope( *$1, TYPEDEFname /*, "10"*/ );
+			typedefTable.addToEnclosingScope( *$1, TYPEDEFname, "10" );
 			$$ = DeclarationNode::newTypeDecl( $1, 0 );
 		}
 	| no_attr_identifier_or_type_name '(' type_parameter_list ')'
 		{
-			typedefTable.addToEnclosingScope( *$1, TYPEGENname /*, "11"*/ );
+			typedefTable.addToEnclosingScope( *$1, TYPEGENname, "11" );
 			$$ = DeclarationNode::newTypeDecl( $1, $3 );
 		}
@@ -2330,8 +2325,22 @@
 	;
 
+	// SKULLDUGGERY: Declarations in extern "X" and distribution need to be added to the current lexical scope.
+	// However, external_definition_list creates a new scope around each external_definition, but the pop loses all the
+	// types in the extern "X" and distribution at the end of the block. This version of external_definition_list does
+
+	// not do push/pop for declarations at the level of the extern "X" and distribution block. Any recursive uses of
+	// external_definition_list within the extern "X" and distribution block correctly pushes/pops for that scope level.
+external_definition_list_no_pop_push:
+	external_definition
+	| external_definition_list_no_pop_push
+		{ forall = xxx; }
+	  external_definition
+		{ $$ = $1 ? $1->appendList( $3 ) : $3; }
+	;
+
 external_definition_list_opt:
 	// empty
 		{ $$ = nullptr; }
-	| external_definition_list
+	| external_definition_list_no_pop_push
 	;
 
@@ -2339,4 +2348,9 @@
 	declaration
 	| external_function_definition
+	| EXTENSION external_definition						// GCC, multiple __extension__ allowed, meaning unknown
+		{
+			distExt( $2 );								// mark all fields in list
+			$$ = $2;
+		}
 	| ASM '(' string_literal ')' ';'					// GCC, global assembler statement
 		{
@@ -2348,22 +2362,13 @@
 			linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 );
 		}
-			// SKULLDUGGERY: Declarations in extern "X" need to be added to the current lexical scope.  However,
-			// external_definition_list_opt creates a new scope that loses the types at the end of the extern block. The
-			// correction is a pop/push (reverse order) to undo the push/pop from external_definition_list_opt.  This
-			// trick works for nested extern "X"s, as each one undoes itself in the nesting.
-	  '{' pop external_definition_list_opt push '}'
+	  '{' external_definition_list_opt '}'
 		{
 			linkage = linkageStack.top();
 			linkageStack.pop();
-			$$ = $6;
-		}
-	| EXTENSION external_definition						// GCC, multiple __extension__ allowed, meaning unknown
-		{
-			distExt( $2 );								// mark all fields in list
-			$$ = $2;
+			$$ = $5;
 		}
 	| type_qualifier_list
 		{ if ( $1->type->forall ) xxx = forall = true; } // remember generic type
-	  '{' external_definition_list push '}'			 // CFA, namespace
+	  '{' external_definition_list_opt '}'				// CFA, namespace
 		{
 			for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
@@ -2378,5 +2383,5 @@
 	| declaration_qualifier_list
 		{ if ( $1->type->forall ) xxx = forall = true; } // remember generic type
-	  '{' external_definition_list '}'					 // CFA, namespace
+	  '{' external_definition_list_opt '}'				// CFA, namespace
 		{
 			for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
@@ -2394,5 +2399,5 @@
 			if ( $2->type->forall ) xxx = forall = true; // remember generic type
 		}
-	  '{' external_definition_list '}'					// CFA, namespace
+	  '{' external_definition_list_opt '}'				// CFA, namespace
 		{
 			for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {
@@ -2715,5 +2720,5 @@
 	typedef
 		// hide type name in enclosing scope by variable name
-		{ typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER /*, "ID"*/ ); }
+		{ typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER, "ID" ); }
 	| '(' paren_type ')'
 		{ $$ = $2; }
