Index: src/Parser/parser.yy
===================================================================
--- src/Parser/parser.yy	(revision f9941ff08adf6cc1d6d77e61ea910cc9f82ecbce)
+++ src/Parser/parser.yy	(revision c38ae927de4734c94eb69a436cca8cc25a347b02)
@@ -10,6 +10,6 @@
 // Created On       : Sat Sep  1 20:22:55 2001
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Oct 25 12:28:54 2017
-// Update Count     : 2893
+// Last Modified On : Mon Nov 20 09:45:36 2017
+// Update Count     : 2945
 //
 
@@ -114,4 +114,16 @@
 	} // for
 } // distExt
+
+// There is an ambiguity for inline generic-routine return-types and generic routines.
+//   forall( otype T ) struct S { int i; } bar( T ) {}
+// Does the forall bind to the struct or the routine, and how would it be possible to explicitly specify the binding.
+//   forall( otype T ) struct S { int T; } forall( otype W ) bar( W ) {}
+
+void rebindForall( DeclarationNode * declSpec, DeclarationNode * funcDecl ) {
+	if ( declSpec->type->kind == TypeData::Aggregate ) { // return is aggregate definition
+		funcDecl->type->forall = declSpec->type->aggregate.params; // move forall from aggregate to function type
+		declSpec->type->aggregate.params = nullptr;
+	} // if
+} // rebindForall
 
 bool forall = false;									// aggregate have one or more forall qualifiers ?
@@ -348,9 +360,8 @@
 
 
-// Handle single shift/reduce conflict for dangling else by shifting the ELSE token. For example, this string
-// is ambiguous:
-// .---------.				matches IF '(' comma_expression ')' statement . (reduce)
-// if ( C ) S1 else S2
-// `-----------------'		matches IF '(' comma_expression ')' statement . (shift) ELSE statement */
+// Handle shift/reduce conflict for dangling else by shifting the ELSE token. For example, this string is ambiguous:
+//   .---------.				matches IF '(' comma_expression ')' statement . (reduce)
+//   if ( C ) S1 else S2
+//   `-----------------'		matches IF '(' comma_expression ')' statement . (shift) ELSE statement */
 // Similar issues exit with the waitfor statement.
 
@@ -361,4 +372,16 @@
 %precedence TIMEOUT	// token precedence for start of TIMEOUT in WAITFOR statement
 %precedence ELSE	// token precedence for start of else clause in IF/WAITFOR statement
+
+// Handle shift/reduce conflict for generic type by shifting the '(' token. For example, this string is ambiguous:
+//   forall( otype T ) struct Foo { T v; };
+//       .-----.				matches pointer to function returning a generic (which is impossible without a type)
+//   Foo ( *fp )( int );
+//   `---'						matches start of TYPEGENname '('
+// Must be:
+// Foo( int ) ( *fp )( int );
+
+// Order of these lines matters (low-to-high precedence).
+%precedence TYPEGENname
+%precedence '('
 
 %locations			// support location tracking for error messages
@@ -1765,5 +1788,7 @@
 
 typegen_name:											// CFA
-	TYPEGENname '(' ')'
+	TYPEGENname
+		{ $$ = DeclarationNode::newFromTypeGen( $1, nullptr ); }
+	| TYPEGENname '(' ')'
 		{ $$ = DeclarationNode::newFromTypeGen( $1, nullptr ); }
 	| TYPEGENname '(' type_list ')'
@@ -1809,5 +1834,13 @@
 		}
 	| aggregate_key attribute_list_opt typegen_name		// CFA
-		{ $$ = $3->addQualifiers( $2 ); }
+		{
+			// Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is
+			// switched to a TYPEGENname. Link any generic arguments from typegen_name to new generic declaration and
+			// delete newFromTypeGen.
+			$$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $3->type->symbolic.actuals, nullptr, false )->addQualifiers( $2 );
+			$3->type->symbolic.name = nullptr;
+			$3->type->symbolic.actuals = nullptr;
+			delete $3;
+		}
 	;
 
@@ -2380,4 +2413,5 @@
 	| declaration_specifier function_declarator with_clause_opt compound_statement
 		{
+			rebindForall( $1, $2 );
 			typedefTable.addToEnclosingScope( TypedefTable::ID );
 			typedefTable.leaveScope();
@@ -2406,4 +2440,5 @@
 	| declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
 		{
+			rebindForall( $1, $2 );
 			typedefTable.addToEnclosingScope( TypedefTable::ID );
 			typedefTable.leaveScope();
