Index: doc/user/user.tex
===================================================================
--- doc/user/user.tex	(revision 2c9ebabd500b086aeb45d01caed3a928fad5b3c2)
+++ doc/user/user.tex	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
@@ -11,6 +11,6 @@
 %% Created On       : Wed Apr  6 14:53:29 2016
 %% Last Modified By : Peter A. Buhr
-%% Last Modified On : Fri May 19 11:54:31 2017
-%% Update Count     : 1735
+%% Last Modified On : Sun May 21 23:36:42 2017
+%% Update Count     : 1822
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
@@ -94,5 +94,5 @@
 \author{
 \huge \CFA Team \medskip \\
-\Large Richard Bilson, Peter A. Buhr, Thierry Delisle, \smallskip \\
+\Large Andrew Beach, Richard Bilson, Peter A. Buhr, Thierry Delisle, \smallskip \\
 \Large Glen Ditchfield, Rodolfo G. Esteves, Aaron Moss, Rob Schluntz
 }% author
@@ -644,13 +644,19 @@
 \end{quote2}
 
-Unsupported are K\&R C declarations where the base type defaults to ©int©, if no type is specified,\footnote{
-At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each structure declaration and type name~\cite[\S~6.7.2(2)]{C11}}
-\eg:
-\begin{cfa}
-x;								§\C{// int x}§
-*y;								§\C{// int *y}§
-f( p1, p2 );					§\C{// int f( int p1, int p2 );}§
-f( p1, p2 ) {}					§\C{// int f( int p1, int p2 ) {}}§
-\end{cfa}
+The new declaration syntax can be used in other contexts where types are required, \eg casts and the pseudo-routine ©sizeof©:
+\begin{quote2}
+\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
+\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}	& \multicolumn{1}{c}{\textbf{C}}	\\
+\begin{cfa}
+y = (®* int®)x;
+i = sizeof(®[ 5 ] * int®);
+\end{cfa}
+&
+\begin{cfa}
+y = (®int *®)x;
+i = sizeof(®int *[ 5 ]®);
+\end{cfa}
+\end{tabular}
+\end{quote2}
 
 Finally, new \CFA declarations may appear together with C declarations in the same program block, but cannot be mixed within a specific declaration.
@@ -1105,23 +1111,4 @@
 > already.
 \end{comment}
-
-
-\section{Type Operators}
-
-The new declaration syntax can be used in other contexts where types are required, \eg casts and the pseudo-routine ©sizeof©:
-\begin{quote2}
-\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
-\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}	& \multicolumn{1}{c}{\textbf{C}}	\\
-\begin{cfa}
-y = (®* int®)x;
-i = sizeof(®[ 5 ] * int®);
-\end{cfa}
-&
-\begin{cfa}
-y = (®int *®)x;
-i = sizeof(®int *[ 5 ]®);
-\end{cfa}
-\end{tabular}
-\end{quote2}
 
 
@@ -4842,164 +4829,41 @@
 
 
-\section{Syntactic Anomalies}
-
-There are several ambiguous cases with operator identifiers, \eg ©int *?*?()©, where the string ©*?*?© can be lexed as ©*©~\R{/}~©?*?© or ©*?©~\R{/}~©*?©.
-Since it is common practise to put a unary operator juxtaposed to an identifier, \eg ©*i©, users will be annoyed if they cannot do this with respect to operator identifiers.
-Even with this special hack, there are 5 general cases that cannot be handled.
-The first case is for the function-call identifier ©?()©:
-\begin{cfa}
-int *§\textvisiblespace§?()();	// declaration: space required after '*'
-*§\textvisiblespace§?()();		// expression: space required after '*'
-\end{cfa}
-Without the space, the string ©*?()© is ambiguous without N character look ahead;
-it requires scanning ahead to determine if there is a ©'('©, which is the start of an argument/parameter list.
-
-The 4 remaining cases occur in expressions:
-\begin{cfa}
-i++§\textvisiblespace§?i:0;		// space required before '?'
-i--§\textvisiblespace§?i:0;		// space required before '?'
-i§\textvisiblespace§?++i:0;		// space required after '?'
-i§\textvisiblespace§?--i:0;		// space required after '?'
-\end{cfa}
-In the first two cases, the string ©i++?© is ambiguous, where this string can be lexed as ©i© / ©++?© or ©i++© / ©?©;
-it requires scanning ahead to determine if there is a ©'('©, which is the start of an argument list.
-In the second two cases, the string ©?++x© is ambiguous, where this string can be lexed as ©?++© / ©x© or ©?© / y©++x©;
-it requires scanning ahead to determine if there is a ©'('©, which is the start of an argument list.
-
-
-\section{Incompatible}
-
-The following incompatibles exist between \CFA and C, and are similar to Annex C for \CC~\cite{C++14}.
-
-\begin{enumerate}
-\item
-\begin{description}
-\item[Change:] add new keywords \\
-New keywords are added to \CFA (see~\VRef{s:NewKeywords}).
-\item[Rationale:] keywords added to implement new semantics of \CFA.
-\item[Effect on original feature:] change to semantics of well-defined feature. \\
-Any ISO C programs using these keywords as identifiers are invalid \CFA programs.
-\item[Difficulty of converting:] keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism (see~\VRef{s:BackquoteIdentifiers}):
-\item[How widely used:] clashes among new \CFA keywords and existing identifiers are rare.
-\end{description}
-
-\item
-\begin{description}
-\item[Change:] type of character literal ©int© to ©char© to allow more intuitive overloading:
-\begin{cfa}
-int rtn( int i );
-int rtn( char c );
-rtn( 'x' );						§\C{// programmer expects 2nd rtn to be called}§
-\end{cfa}
-\item[Rationale:] it is more intuitive for the call to ©rtn© to match the second version of definition of ©rtn© rather than the first.
-In particular, output of ©char© variable now print a character rather than the decimal ASCII value of the character.
-\begin{cfa}
-sout | 'x' | " " | (int)'x' | endl;
-x 120
-\end{cfa}
-Having to cast ©'x'© to ©char© is non-intuitive.
-\item[Effect on original feature:] change to semantics of well-defined feature that depend on:
-\begin{cfa}
-sizeof( 'x' ) == sizeof( int )
-\end{cfa}
-no long work the same in \CFA programs.
-\item[Difficulty of converting:] simple
-\item[How widely used:] programs that depend upon ©sizeof( 'x' )© are rare and can be changed to ©sizeof(char)©.
-\end{description}
-
-\item
-\begin{description}
-\item[Change:] make string literals ©const©:
-\begin{cfa}
-char * p = "abc";				§\C{// valid in C, deprecated in \CFA}§
-char * q = expr ? "abc" : "de";	§\C{// valid in C, invalid in \CFA}§
-\end{cfa}
-The type of a string literal is changed from ©[] char© to ©const [] char©.
-Similarly, the type of a wide string literal is changed from ©[] wchar_t© to ©const [] wchar_t©.
-\item[Rationale:] This change is a safety issue:
-\begin{cfa}
-char * p = "abc";
-p[0] = 'w';						§\C{// segment fault or change constant literal}§
-\end{cfa}
-The same problem occurs when passing a string literal to a routine that changes its argument.
-\item[Effect on original feature:] change to semantics of well-defined feature.
-\item[Difficulty of converting:] simple syntactic transformation, because string literals can be converted to ©char *©.
-\item[How widely used:] programs that have a legitimate reason to treat string literals as pointers to potentially modifiable memory are rare.
-\end{description}
-
-\item
-\begin{description}
-\item[Change:] remove \newterm{tentative definitions}, which only occurs at file scope:
-\begin{cfa}
-int i;							§\C{// forward definition}§
-int *j = ®&i®;					§\C{// forward reference, valid in C, invalid in \CFA}§
-int i = 0;						§\C{// definition}§
-\end{cfa}
-is valid in C, and invalid in \CFA because duplicate overloaded object definitions at the same scope level are disallowed.
-This change makes it impossible to define mutually referential file-local static objects, if initializers are restricted to the syntactic forms of C. For example,
-\begin{cfa}
-struct X { int i; struct X *next; };
-static struct X a;				§\C{// forward definition}§
-static struct X b = { 0, ®&a® };	§\C{// forward reference, valid in C, invalid in \CFA}§
-static struct X a = { 1, &b };	§\C{// definition}§
-\end{cfa}
-\item[Rationale:] avoids having different initialization rules for builtin types and userdefined types.
-\item[Effect on original feature:] change to semantics of well-defined feature.
-\item[Difficulty of converting:] the initializer for one of a set of mutually-referential file-local static objects must invoke a routine call to achieve the initialization.
-\item[How widely used:] seldom
-\end{description}
-
-\item
-\begin{description}
-\item[Change:] have ©struct© introduce a scope for nested types:
-\begin{cfa}
-enum ®Colour® { R, G, B, Y, C, M };
-struct Person {
-	enum ®Colour® { R, G, B };	§\C{// nested type}§
-	struct Face {				§\C{// nested type}§
-		®Colour® Eyes, Hair;	§\C{// type defined outside (1 level)}§
-	};
-	ß.ß®Colour® shirt;			§\C{// type defined outside (top level)}§
-	®Colour® pants;				§\C{// type defined same level}§
-	Face looks[10];				§\C{// type defined same level}§
-};
-®Colour® c = R;					§\C{// type/enum defined same level}§
-Personß.ß®Colour® pc = Personß.ßR;	§\C{// type/enum defined inside}§
-Personß.ßFace pretty;			§\C{// type defined inside}§
-\end{cfa}
-In C, the name of the nested types belongs to the same scope as the name of the outermost enclosing structure, \ie the nested types are hoisted to the scope of the outer-most type, which is not useful and confusing.
-\CFA is C \emph{incompatible} on this issue, and provides semantics similar to \Index*[C++]{\CC}.
-Nested types are not hoisted and can be referenced using the field selection operator ``©.©'', unlike the \CC scope-resolution operator ``©::©''.
-\item[Rationale:] ©struct© scope is crucial to \CFA as an information structuring and hiding mechanism.
-\item[Effect on original feature:] change to semantics of well-defined feature.
-\item[Difficulty of converting:] Semantic transformation.
-\item[How widely used:] C programs rarely have nest types because they are equivalent to the hoisted version.
-\end{description}
-
-\item
-\begin{description}
-\item[Change:] In C++, the name of a nested class is local to its enclosing class.
-\item[Rationale:] C++ classes have member functions which require that classes establish scopes.
-\item[Difficulty of converting:] Semantic transformation. To make the struct type name visible in the scope of the enclosing struct, the struct tag could be declared in the scope of the enclosing struct, before the enclosing struct is defined. Example:
-\begin{cfa}
-struct Y;						§\C{// struct Y and struct X are at the same scope}§
-struct X {
-struct Y { /* ... */ } y;
-};
-\end{cfa}
-All the definitions of C struct types enclosed in other struct definitions and accessed outside the scope of the enclosing struct could be exported to the scope of the enclosing struct.
-Note: this is a consequence of the difference in scope rules, which is documented in 3.3.
-\item[How widely used:] Seldom.
-\end{description}
-
-\item
-\begin{description}
-\item[Change:] comma expression is disallowed as subscript
-\item[Rationale:] safety issue to prevent subscripting error for multidimensional arrays: ©x[i,j]© instead of ©x[i][j]©, and this syntactic form then taken by \CFA for new style arrays.
-\item[Effect on original feature:] change to semantics of well-defined feature.
-\item[Difficulty of converting:] semantic transformation of ©x[i,j]© to ©x[(i,j)]©
-\item[How widely used:] seldom.
-\end{description}
-\end{enumerate}
+\section{Syntax Ambiguities}
+
+C has a number of syntax ambiguities, which are resolved by taking the longest sequence of overlapping characters that constitute a token.
+For example, the program fragment ©x+++++y© is parsed as \lstinline[showspaces=true]@x ++ ++ + y@ because operator tokens ©++© and ©+© overlap.
+Unfortunately, the longest sequence violates a constraint on increment operators, even though the parse \lstinline[showspaces=true]@x ++ + ++ y@ might yield a correct expression.
+Hence, C programmers are aware that spaces have to added to disambiguate certain syntactic cases.
+
+In \CFA, there are ambiguous cases with dereference and operator identifiers, \eg ©int *?*?()©, where the string ©*?*?© can be interpreted as:
+\begin{cfa}
+*?§\color{red}\textvisiblespace§*?		§\C{// dereference operator, dereference operator}§
+*§\color{red}\textvisiblespace§?*?		§\C{// dereference, multiplication operator}§
+\end{cfa}
+By default, the first interpretation is selected, which does not yield a meaningful parse.
+Therefore, \CFA does a lexical look-ahead for the second case, and backtracks to return the leading unary operator and reparses the trailing operator identifier.
+Otherwise a space is needed between the unary operator and operator identifier to disambiguate this common case.
+
+A similar issue occurs with the dereference, ©*?(...)©, and routine-call, ©?()(...)© identifiers.
+The ambiguity occurs when the deference operator has no parameters:
+\begin{cfa}
+*?()§\color{red}\textvisiblespace...§ ;
+*?()§\color{red}\textvisiblespace...§(...) ;
+\end{cfa}
+requiring arbitrary whitespace look-ahead for the routine-call parameter-list to disambiguate.
+However, the dereference operator \emph{must} have a parameter/argument to dereference ©*?(...)©.
+Hence, always interpreting the string ©*?()© as \lstinline[showspaces=true]@* ?()@ does not preclude any meaningful program.
+
+The remaining cases are with the increment/decrement operators and conditional expression, \eg:
+\begin{cfa}
+i++?§\color{red}\textvisiblespace...§(...);
+i?++§\color{red}\textvisiblespace...§(...);
+\end{cfa}
+requiring arbitrary whitespace look-ahead for the operator parameter-list, even though that interpretation is an incorrect expression (juxtaposed identifiers).
+Therefore, it is necessary to disambiguate these cases with a space:
+\begin{cfa}
+i++§\color{red}\textvisiblespace§? i : 0;
+i?§\color{red}\textvisiblespace§++i : 0;
+\end{cfa}
 
 
@@ -5008,5 +4872,5 @@
 
 \begin{quote2}
-\begin{tabular}{lll}
+\begin{tabular}{llll}
 \begin{tabular}{@{}l@{}}
 ©_AT©			\\
@@ -5016,22 +4880,25 @@
 ©coroutine©		\\
 ©disable©		\\
-©dtype©			\\
-©enable©		\\
 \end{tabular}
 &
 \begin{tabular}{@{}l@{}}
+©dtype©			\\
+©enable©		\\
 ©fallthrough©	\\
 ©fallthru©		\\
 ©finally©		\\
 ©forall©		\\
+\end{tabular}
+&
+\begin{tabular}{@{}l@{}}
 ©ftype©			\\
 ©lvalue©		\\
 ©monitor©		\\
 ©mutex©			\\
+©one_t©			\\
+©otype©			\\
 \end{tabular}
 &
 \begin{tabular}{@{}l@{}}
-©one_t©			\\
-©otype©			\\
 ©throw©			\\
 ©throwResume©	\\
@@ -5043,4 +4910,168 @@
 \end{tabular}
 \end{quote2}
+
+
+\section{Incompatible}
+
+The following incompatibles exist between \CFA and C, and are similar to Annex C for \CC~\cite{C++14}.
+
+
+\begin{enumerate}
+\item
+\begin{description}
+\item[Change:] add new keywords \\
+New keywords are added to \CFA (see~\VRef{s:CFAKeywords}).
+\item[Rationale:] keywords added to implement new semantics of \CFA.
+\item[Effect on original feature:] change to semantics of well-defined feature. \\
+Any ISO C programs using these keywords as identifiers are invalid \CFA programs.
+\item[Difficulty of converting:] keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism (see~\VRef{s:BackquoteIdentifiers}).
+\item[How widely used:] clashes among new \CFA keywords and existing identifiers are rare.
+\end{description}
+
+\item
+\begin{description}
+\item[Change:] drop K\&R C declarations \\
+K\&R declarations allow an implicit base-type of ©int©, if no type is specified, plus an alternate syntax for declaring parameters.
+\eg:
+\begin{cfa}
+x;								§\C{// int x}§
+*y;								§\C{// int *y}§
+f( p1, p2 );					§\C{// int f( int p1, int p2 );}§
+g( p1, p2 ) int p1, p2;			§\C{// int g( int p1, int p2 );}§
+\end{cfa}
+\CFA supports K\&R routine definitions:
+\begin{cfa}
+f( a, b, c )					§\C{// default int return}§
+	int a, b; char c			§\C{// K\&R parameter declarations}§
+{
+	...
+}
+\end{cfa}
+\item[Rationale:] dropped from C11 standard.\footnote{
+At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each structure declaration and type name~\cite[\S~6.7.2(2)]{C11}}
+\item[Effect on original feature:] original feature is deprecated. \\
+Any old C programs using these K\&R declarations are invalid \CFA programs.
+\item[Difficulty of converting:] trivial to convert to \CFA.
+\item[How widely used:] existing usages are rare.
+\end{description}
+
+\item
+\begin{description}
+\item[Change:] type of character literal ©int© to ©char© to allow more intuitive overloading:
+\begin{cfa}
+int rtn( int i );
+int rtn( char c );
+rtn( 'x' );						§\C{// programmer expects 2nd rtn to be called}§
+\end{cfa}
+\item[Rationale:] it is more intuitive for the call to ©rtn© to match the second version of definition of ©rtn© rather than the first.
+In particular, output of ©char© variable now print a character rather than the decimal ASCII value of the character.
+\begin{cfa}
+sout | 'x' | " " | (int)'x' | endl;
+x 120
+\end{cfa}
+Having to cast ©'x'© to ©char© is non-intuitive.
+\item[Effect on original feature:] change to semantics of well-defined feature that depend on:
+\begin{cfa}
+sizeof( 'x' ) == sizeof( int )
+\end{cfa}
+no long work the same in \CFA programs.
+\item[Difficulty of converting:] simple
+\item[How widely used:] programs that depend upon ©sizeof( 'x' )© are rare and can be changed to ©sizeof(char)©.
+\end{description}
+
+\item
+\begin{description}
+\item[Change:] make string literals ©const©:
+\begin{cfa}
+char * p = "abc";				§\C{// valid in C, deprecated in \CFA}§
+char * q = expr ? "abc" : "de";	§\C{// valid in C, invalid in \CFA}§
+\end{cfa}
+The type of a string literal is changed from ©[] char© to ©const [] char©.
+Similarly, the type of a wide string literal is changed from ©[] wchar_t© to ©const [] wchar_t©.
+\item[Rationale:] This change is a safety issue:
+\begin{cfa}
+char * p = "abc";
+p[0] = 'w';						§\C{// segment fault or change constant literal}§
+\end{cfa}
+The same problem occurs when passing a string literal to a routine that changes its argument.
+\item[Effect on original feature:] change to semantics of well-defined feature.
+\item[Difficulty of converting:] simple syntactic transformation, because string literals can be converted to ©char *©.
+\item[How widely used:] programs that have a legitimate reason to treat string literals as pointers to potentially modifiable memory are rare.
+\end{description}
+
+\item
+\begin{description}
+\item[Change:] remove \newterm{tentative definitions}, which only occurs at file scope:
+\begin{cfa}
+int i;							§\C{// forward definition}§
+int *j = ®&i®;					§\C{// forward reference, valid in C, invalid in \CFA}§
+int i = 0;						§\C{// definition}§
+\end{cfa}
+is valid in C, and invalid in \CFA because duplicate overloaded object definitions at the same scope level are disallowed.
+This change makes it impossible to define mutually referential file-local static objects, if initializers are restricted to the syntactic forms of C. For example,
+\begin{cfa}
+struct X { int i; struct X *next; };
+static struct X a;				§\C{// forward definition}§
+static struct X b = { 0, ®&a® };	§\C{// forward reference, valid in C, invalid in \CFA}§
+static struct X a = { 1, &b };	§\C{// definition}§
+\end{cfa}
+\item[Rationale:] avoids having different initialization rules for builtin types and userdefined types.
+\item[Effect on original feature:] change to semantics of well-defined feature.
+\item[Difficulty of converting:] the initializer for one of a set of mutually-referential file-local static objects must invoke a routine call to achieve the initialization.
+\item[How widely used:] seldom
+\end{description}
+
+\item
+\begin{description}
+\item[Change:] have ©struct© introduce a scope for nested types:
+\begin{cfa}
+enum ®Colour® { R, G, B, Y, C, M };
+struct Person {
+	enum ®Colour® { R, G, B };	§\C{// nested type}§
+	struct Face {				§\C{// nested type}§
+		®Colour® Eyes, Hair;	§\C{// type defined outside (1 level)}§
+	};
+	®.Colour® shirt;			§\C{// type defined outside (top level)}§
+	®Colour® pants;				§\C{// type defined same level}§
+	Face looks[10];				§\C{// type defined same level}§
+};
+®Colour® c = R;					§\C{// type/enum defined same level}§
+Person®.Colour® pc = Person®.®R;	§\C{// type/enum defined inside}§
+Person®.®Face pretty;			§\C{// type defined inside}§
+\end{cfa}
+In C, the name of the nested types belongs to the same scope as the name of the outermost enclosing structure, \ie the nested types are hoisted to the scope of the outer-most type, which is not useful and confusing.
+\CFA is C \emph{incompatible} on this issue, and provides semantics similar to \Index*[C++]{\CC}.
+Nested types are not hoisted and can be referenced using the field selection operator ``©.©'', unlike the \CC scope-resolution operator ``©::©''.
+\item[Rationale:] ©struct© scope is crucial to \CFA as an information structuring and hiding mechanism.
+\item[Effect on original feature:] change to semantics of well-defined feature.
+\item[Difficulty of converting:] Semantic transformation.
+\item[How widely used:] C programs rarely have nest types because they are equivalent to the hoisted version.
+\end{description}
+
+\item
+\begin{description}
+\item[Change:] In C++, the name of a nested class is local to its enclosing class.
+\item[Rationale:] C++ classes have member functions which require that classes establish scopes.
+\item[Difficulty of converting:] Semantic transformation. To make the struct type name visible in the scope of the enclosing struct, the struct tag could be declared in the scope of the enclosing struct, before the enclosing struct is defined. Example:
+\begin{cfa}
+struct Y;						§\C{// struct Y and struct X are at the same scope}§
+struct X {
+struct Y { /* ... */ } y;
+};
+\end{cfa}
+All the definitions of C struct types enclosed in other struct definitions and accessed outside the scope of the enclosing struct could be exported to the scope of the enclosing struct.
+Note: this is a consequence of the difference in scope rules, which is documented in 3.3.
+\item[How widely used:] Seldom.
+\end{description}
+
+\item
+\begin{description}
+\item[Change:] comma expression is disallowed as subscript
+\item[Rationale:] safety issue to prevent subscripting error for multidimensional arrays: ©x[i,j]© instead of ©x[i][j]©, and this syntactic form then taken by \CFA for new style arrays.
+\item[Effect on original feature:] change to semantics of well-defined feature.
+\item[Difficulty of converting:] semantic transformation of ©x[i,j]© to ©x[(i,j)]©
+\item[How widely used:] seldom.
+\end{description}
+\end{enumerate}
 
 
@@ -5080,18 +5111,22 @@
 \leavevmode
 \begin{cfa}[aboveskip=0pt,belowskip=0pt]
-forall( otype T ) T * malloc( void );§\indexc{malloc}§
-forall( otype T ) T * malloc( char fill );
-forall( otype T ) T * malloc( T * ptr, size_t size );
-forall( otype T ) T * malloc( T * ptr, size_t size, unsigned char fill );
-forall( otype T ) T * calloc( size_t nmemb );§\indexc{calloc}§
-forall( otype T ) T * realloc( T * ptr, size_t size );§\indexc{ato}§
-forall( otype T ) T * realloc( T * ptr, size_t size, unsigned char fill );
-
-forall( otype T ) T * aligned_alloc( size_t alignment );§\indexc{ato}§
-forall( otype T ) T * memalign( size_t alignment );		// deprecated
-forall( otype T ) int posix_memalign( T ** ptr, size_t alignment );
+forall( dtype T | sized(T) ) T * malloc( void );§\indexc{malloc}§
+forall( dtype T | sized(T) ) T * malloc( char fill );
+forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size );
+forall( dtype T | sized(T) ) T * malloc( T * ptr, size_t size, unsigned char fill );
+forall( dtype T | sized(T) ) T * calloc( size_t nmemb );§\indexc{calloc}§
+forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size );§\indexc{ato}§
+forall( dtype T | sized(T) ) T * realloc( T * ptr, size_t size, unsigned char fill );
+
+forall( dtype T | sized(T) ) T * aligned_alloc( size_t alignment );§\indexc{ato}§
+forall( dtype T | sized(T) ) T * memalign( size_t alignment );		// deprecated
+forall( dtype T | sized(T) ) int posix_memalign( T ** ptr, size_t alignment );
 
 forall( otype T ) T * memset( T * ptr, unsigned char fill ); // use default value '\0' for fill
 forall( otype T ) T * memset( T * ptr );				// remove when default value available
+
+forall( dtype T, ttype Params | sized(T) | { void ?{}(T *, Params); } ) T * new( Params p );
+forall( dtype T | { void ^?{}(T *); } ) void delete( T * ptr );
+forall( dtype T, ttype Params | { void ^?{}(T *); void delete(Params); } ) void delete( T * ptr, Params rest );
 \end{cfa}
 
Index: c/working/exception/README
===================================================================
--- doc/working/exception/README	(revision 2c9ebabd500b086aeb45d01caed3a928fad5b3c2)
+++ 	(revision )
@@ -1,9 +1,0 @@
-This folder contains a working prototype of how to implement exceptions in C.
-
-main.cfa	: Example user code
-main.c	: Example generated code
-except.c	: Implementation of the unwinding logic
-except.h	: header for except
-lsda.h	: stolen code from gcc that handles reading the exception table language specifica data
-
-to compile run : "gcc -fexceptions -Wall -Werror -g main.c except.c"
Index: doc/working/exception/design.txt
===================================================================
--- doc/working/exception/design.txt	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
+++ doc/working/exception/design.txt	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
@@ -0,0 +1,140 @@
+Design of Exceptions and EHM in Cforall:
+
+Currently this is a combination of ideas and big questions that still have to
+be addressed. It also includes some other error handling options, how they
+interact and compare to exceptions.
+
+
+What is an Exception:
+
+In other words what do we throw? What is matched against, how does it carry
+data with it? A very important question that has not been answered.
+
+Option 1: Strutures
+
+Considering the current state of Cforall the most natural form of the
+exception would likely be a struture, implementing a trait repersenting the
+minimum features of an exception. This has many advantages, including arbitray
+fields, some polymorphism and it matches exceptations of many current systems.
+
+The main issue with this is matching, without OOP inheritance there is no
+exception hierarchy. Meaning all handling has to happen on the exact exception
+without the ease of grouping parents. There are several ways to attempt to
+recover this.
+
+The first is with conditional matching (a check after the type has been
+matched) which allows for matching particular values of a known type. However
+this does not dynamically expand and requires an extra step (as opposed to
+mearly allowing one). I would not recomend this as the primary method.
+
+Second is to try and use type casts/conversions to create an implicate
+hierachy, so that a catch clause catches anything of the given type or
+anything that converts to the given type.
+
+Plan9 (from what I know of it) would be a powerful tool here. Even with it,
+creating a hierarchy of types at runtime might be too expencive. Esecially
+since they are less likely to be tree like at that point.
+
+Option 2: Tags
+
+The other option is to introduce a new construct into the language. A tag
+repersents a type of exception, it is not a structure or variable (or even
+a normal type). It may be usable in some of those contexts.
+
+Tags can declare an existing tag as its parent. Tags can be caught by handlers
+that catch their parents. (There is a single base_exception that all other
+exceptions are children of eventually.) This allows for grouping of exceptions
+that repersent similar errors.
+
+Tags should also have some assotiated data, where and on what did the error
+occur. Keeping with the otherness of exception tags and allowing them to be
+expanded, using a parameter list. Each exception can have a list of paramters
+given to it on a throw. Each tag would have a declared list of parameters
+(which could be treated more like a set of fields as well). Child tags must
+use their parent's list as a prefix to their own, so that the parameters can
+be accessed when the child tag is matched against the parent.
+
+Option N: ...
+
+This list is not complete.
+
+
+Seperating Termination and Resumption:
+
+Differentating the types of exceptions based on exception would be hard with
+exceptions as structures. It is possible with exceptions as tags by having
+two base exceptions, one for each type of throw. However recompining them
+to dual types would be harder.
+
+Reguardless, using different keywords would also be useful for clarity, even
+if it does not add functality. Using the C++ like keywords would be a good
+base. Resumption exceptions could use a different set (ex. raise->handle) or
+use resume as a qualifier on the existing statements.
+
+
+Conditional Matching:
+
+A possible useful feature, it allows for arbitrary checks on a catch block
+instead of merely matching a type. However there are few use cases that
+cannot be avoided with proper use of a type hierarchy, and this shrinks even
+further with a good use of re-throws.
+
+Also it assumes one sweep, that might also be a problem. But might also give
+it an advantage over re-throws.
+
+
+Alternatives: Implicate Handlers & Return Unions
+
+Both act as a kind of local version of an exception. Implicate handlers act as
+resumption exceptions and return unions like termination exceptions. By local
+I mean they work well at one or two levels of calls, but do not cover N levels
+as cleanly.
+
+Implicate handles require a growing number of function pointers (which should
+not be used very often) to be passed to functions, creating and additional
+preformance cost. Return unions have to be checked and handled at every level,
+which has some preformance cost, but also can significantly clutter code.
+Proper tools can help with the latter.
+
+However, they may work better at that local level as they do not require stack
+walking or unwinding. In addition they are closer to regular control flow and
+are easier to staticly check. So even if they can't replace exceptions
+(directly) they may still be worth using together.
+
+For instance, consider the Python iterator interface. It uses a single
+function, __next__, to access the next value and to signal the end of the
+sequence. If a value is returned, it is the next value, if the StopIteration
+exception is thrown the sequence has finished.
+
+However almost every use of an iterator will add a try-except block around the
+call site (possibly through for or next) to catch and handle the exception
+immediately, ignoring the advantages of more distant exception handling.
+
+In this case it may be cleaner to use a Maybe for both cases (as in Rust)
+which gives similar results without having to jump to the exception handler.
+This will likely handle the error case more efficiently and the success case a
+bit less so.
+
+It also mixes the error and regular control flow, which can hurt readablity,
+but very little if the handling is simple, for instance providing a default
+value. Similarly, if the error (or alternate outcome) is common enough
+encoding it in the function signature may be good commuication.
+
+In short, these errors seem to be more effective when errors are likely and
+immediate. High failure operations, especially ones with failures that can
+be handled locally, might be better off using these instead of exceptions.
+
+Also the implicate handlers and return unions could use exceptions as well.
+For instance, a useful default might handler might be to throw an exception,
+seaching up the stack for a solution if one is not locally provided.
+
+Or here is a possible helper for unpacking a Result value:
+		forall(otype T, otype E | exception(E))
+		T get_or_throw (Result(T, E) * this) {
+			if (is_success(this)) {
+				return get_success(this);
+			} else {
+				throw get_failure(this);
+			}
+		}
+So they can feed off of each other.
Index: c/working/exception/except.c
===================================================================
--- doc/working/exception/except.c	(revision 2c9ebabd500b086aeb45d01caed3a928fad5b3c2)
+++ 	(revision )
@@ -1,217 +1,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <unwind.h>
-
-#include "lsda.h"
-
-//Global which defines the current exception
-//Currently an int just to make matching easier
-int this_exception;
-
-//This is our personality routine
-//For every stack frame anotated with ".cfi_personality 0x3,__gcfa_personality_v0"
-//This function will be called twice when unwinding
-//Once in the search phased and once in the cleanup phase
-_Unwind_Reason_Code __gcfa_personality_v0 (
-                     int version, _Unwind_Action actions, unsigned long long exceptionClass,
-                     struct _Unwind_Exception* unwind_exception, struct _Unwind_Context* context)
-{
-	//DEBUG
-	printf("Personality function (%d, %x, %llu, %p, %p):", version, actions, exceptionClass, unwind_exception, context);
-
-	//If we've reached the end of the stack then there is nothing much we can do...
-	if( actions & _UA_END_OF_STACK ) return _URC_END_OF_STACK;
-	
-	//DEBUG
-	if (actions & _UA_SEARCH_PHASE) {
-		printf(" lookup phase");
-	} 
-	//DEBUG
-	else if (actions & _UA_CLEANUP_PHASE) {
-		printf(" cleanup phase");
-	}
-	//Just in case, probably can't actually happen
-	else {
-		printf(" error\n");
-		return _URC_FATAL_PHASE1_ERROR;
-	}
-	
-	//Get a pointer to the language specific data from which we will read what we need
-	const unsigned char * lsd = (const unsigned char*) _Unwind_GetLanguageSpecificData( context );
-
-	if( !lsd ) {	//Nothing to do, keep unwinding
-		printf(" no LSD");
-		goto UNWIND;
-	}
-
-	//Get the instuction pointer and a reading pointer into the exception table
-	lsda_header_info lsd_info;
-	const unsigned char * cur_ptr = parse_lsda_header( context, lsd, &lsd_info);
-	_Unwind_Ptr instruction_ptr = _Unwind_GetIP( context );
-
-	//Linearly search the table for stuff to do
-	while( cur_ptr < lsd_info.action_table ) {
-		_Unwind_Ptr callsite_start;
-		_Unwind_Ptr callsite_len;
-		_Unwind_Ptr callsite_landing_pad;
-		_uleb128_t  callsite_action;
-
-		//Decode the common stuff we have in here
-		cur_ptr = read_encoded_value (0, lsd_info.call_site_encoding, cur_ptr, &callsite_start);
-		cur_ptr = read_encoded_value (0, lsd_info.call_site_encoding, cur_ptr, &callsite_len);
-		cur_ptr = read_encoded_value (0, lsd_info.call_site_encoding, cur_ptr, &callsite_landing_pad);
-		cur_ptr = read_uleb128 (cur_ptr, &callsite_action);
-
-		//Have we reach the correct frame info yet?
-		if( lsd_info.Start + callsite_start + callsite_len < instruction_ptr ) {
-			//DEBUG BEGIN
-			void * ls = (void*)lsd_info.Start;
-			void * cs = (void*)callsite_start;
-			void * cl = (void*)callsite_len;
-			void * bp = (void*)lsd_info.Start + callsite_start;
-			void * ep = (void*)lsd_info.Start + callsite_start + callsite_len;
-			void * ip = (void*)instruction_ptr;
-			printf("\nfound %p - %p (%p, %p, %p), looking for %p\n", bp, ep, ls, cs, cl, ip);
-			//DEBUG END
-			continue;
-		}
-		
-		//Have we gone too far
-		if( lsd_info.Start + callsite_start > instruction_ptr ) {
-			printf(" gone too far");
-			break;
-		}
-
-		//Something to do?
-		if( callsite_landing_pad ) {
-			//Which phase are we in
-			if (actions & _UA_SEARCH_PHASE) {
-				//Search phase, this means we probably found a potential handler and must check if it is a match
-
-				//If we have arbitrarily decided that 0 means nothing to do and 1 means there is a potential handler
-				//This doesn't seem to conflict the gcc default behavior
-				if (callsite_action != 0) {
-					//Now we want to run some code to see if the handler matches
-					//This is the tricky part where we want to the power to run arbitrary code
-					//However, generating a new exception table entry and try routine every time 
-					//is way more expansive than we might like
-					//The information we have is :
-					//  - The GR (???)
-					//  - The instruction pointer
-					//  - The instruction pointer info (???)
-					//  - The CFA (???)
-					//  - The BSP (Probably the base stack pointer)
-
-
-					//The current apprach uses one exception table entry per try block
-					_uleb128_t imatcher;
-					//Get the relative offset to the 
-					cur_ptr = read_uleb128 (cur_ptr, &imatcher);
-
-					//Get a function pointer from the relative offset and call it
-					_Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher;					
-					_Unwind_Reason_Code ret = matcher();
-
-					//Based on the return value, check if we matched the exception
-					if( ret == _URC_HANDLER_FOUND) printf(" handler found\n");
-					else printf(" no handler\n");
-					return ret;
-				}
-
-				//This is only a cleanup handler, ignore it
-				printf(" no action");
-			} 
-			else if (actions & _UA_CLEANUP_PHASE) {
-
-				if( (callsite_action != 0) && !(actions & _UA_HANDLER_FRAME) ){
-					//If this is a potential exception handler 
-					//but not the one that matched the exception in the seach phase,
-					//just ignore it
-					goto UNWIND;
-				}
-
-				//We need to run some clean-up or a handler
-				//These statment do the right thing but I don't know any specifics at all
-				_Unwind_SetGR( context, __builtin_eh_return_data_regno(0), (_Unwind_Ptr) unwind_exception );
-				_Unwind_SetGR( context, __builtin_eh_return_data_regno(1), 0 );
-
-				//I assume this sets the instruction pointer to the adress of the landing pad
-				//It doesn't actually set it, it only state the value that needs to be set once we return _URC_INSTALL_CONTEXT
-				_Unwind_SetIP( context, lsd_info.LPStart + callsite_landing_pad );
-
-				//DEBUG
-				printf(" action\n");
-
-				//Return have some action to run
-				return _URC_INSTALL_CONTEXT;
-			}
-		}
-
-		//Nothing to do, move along
-		printf(" no landing pad");
-	}
-	//No handling found
-	printf(" table end reached\n");
-
-	//DEBUG
-	UNWIND:
-	printf(" unwind\n");
-
-	//Keep unwinding the stack
-	return _URC_CONTINUE_UNWIND;
-}
-
-//We need a piece of storage to raise the exception
-struct _Unwind_Exception this_exception_storage;
-
-//Function needed by force unwind
-//It basically says to unwind the whole stack and then exit when we reach the end of the stack
-static _Unwind_Reason_Code _Stop_Fn(	
-	int version, 
-	_Unwind_Action actions, 
-	_Unwind_Exception_Class exceptionClass, 
-	struct _Unwind_Exception * unwind_exception, 
-	struct _Unwind_Context * context, 
-	void * some_param
-) {
-	if( actions & _UA_END_OF_STACK  ) exit(1);
-	if( actions & _UA_CLEANUP_PHASE ) return _URC_NO_REASON;
-
-	return _URC_FATAL_PHASE2_ERROR;
-}
-
-//Example throw routine
-void throw( int val ) {
-	//Store the current exception
-	this_exception = val;
-
-	//DEBUG
-	printf("Throwing exception %d\n", this_exception);
-
-	//Call stdlibc to raise the exception
-	_Unwind_Reason_Code ret = _Unwind_RaiseException( &this_exception_storage );
-
-	//If we reach here it means something happened
-	//For resumption to work we need to find a way to return back to here
-	//Most of them will probably boil down to setting a global flag and making the phase 1 either stop or fail.
-	//Causing an error on purpose may help avoiding unnecessary work but it might have some weird side effects.
-	//If we just pretend no handler was found that would work but may be expensive for no reason since we will always
-	//search the whole stack
-
-	if( ret == _URC_END_OF_STACK ) {
-		//No proper handler was found
-		//This can be handled in several way
-		//C++ calls std::terminate
-		//Here we force unwind the stack, basically raising a cancellation
-		printf("Uncaught exception %p\n", &this_exception_storage);
-		
-		ret = _Unwind_ForcedUnwind( &this_exception_storage, _Stop_Fn, (void*)0x22 );
-		printf("UNWIND ERROR %d after force unwind\n", ret);
-		abort();
-	}
-
-	//We did not simply reach the end of the stack without finding a handler,
-	//Something wen't wrong
-	printf("UNWIND ERROR %d after raise exception\n", ret);
-	abort();
-}
Index: c/working/exception/except.h
===================================================================
--- doc/working/exception/except.h	(revision 2c9ebabd500b086aeb45d01caed3a928fad5b3c2)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#include <unwind.h>
-
-void throw( int val );
Index: doc/working/exception/impl/README
===================================================================
--- doc/working/exception/impl/README	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
+++ doc/working/exception/impl/README	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
@@ -0,0 +1,9 @@
+This folder contains a working prototype of how to implement exceptions in C.
+
+main.cfa	: Example user code
+main.c	: Example generated code
+except.c	: Implementation of the unwinding logic
+except.h	: header for except
+lsda.h	: stolen code from gcc that handles reading the exception table language specifica data
+
+to compile run : "gcc -fexceptions -Wall -Werror -g main.c except.c"
Index: doc/working/exception/impl/except.c
===================================================================
--- doc/working/exception/impl/except.c	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
+++ doc/working/exception/impl/except.c	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
@@ -0,0 +1,217 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <unwind.h>
+
+#include "lsda.h"
+
+//Global which defines the current exception
+//Currently an int just to make matching easier
+int this_exception;
+
+//This is our personality routine
+//For every stack frame anotated with ".cfi_personality 0x3,__gcfa_personality_v0"
+//This function will be called twice when unwinding
+//Once in the search phased and once in the cleanup phase
+_Unwind_Reason_Code __gcfa_personality_v0 (
+                     int version, _Unwind_Action actions, unsigned long long exceptionClass,
+                     struct _Unwind_Exception* unwind_exception, struct _Unwind_Context* context)
+{
+	//DEBUG
+	printf("Personality function (%d, %x, %llu, %p, %p):", version, actions, exceptionClass, unwind_exception, context);
+
+	//If we've reached the end of the stack then there is nothing much we can do...
+	if( actions & _UA_END_OF_STACK ) return _URC_END_OF_STACK;
+	
+	//DEBUG
+	if (actions & _UA_SEARCH_PHASE) {
+		printf(" lookup phase");
+	} 
+	//DEBUG
+	else if (actions & _UA_CLEANUP_PHASE) {
+		printf(" cleanup phase");
+	}
+	//Just in case, probably can't actually happen
+	else {
+		printf(" error\n");
+		return _URC_FATAL_PHASE1_ERROR;
+	}
+	
+	//Get a pointer to the language specific data from which we will read what we need
+	const unsigned char * lsd = (const unsigned char*) _Unwind_GetLanguageSpecificData( context );
+
+	if( !lsd ) {	//Nothing to do, keep unwinding
+		printf(" no LSD");
+		goto UNWIND;
+	}
+
+	//Get the instuction pointer and a reading pointer into the exception table
+	lsda_header_info lsd_info;
+	const unsigned char * cur_ptr = parse_lsda_header( context, lsd, &lsd_info);
+	_Unwind_Ptr instruction_ptr = _Unwind_GetIP( context );
+
+	//Linearly search the table for stuff to do
+	while( cur_ptr < lsd_info.action_table ) {
+		_Unwind_Ptr callsite_start;
+		_Unwind_Ptr callsite_len;
+		_Unwind_Ptr callsite_landing_pad;
+		_uleb128_t  callsite_action;
+
+		//Decode the common stuff we have in here
+		cur_ptr = read_encoded_value (0, lsd_info.call_site_encoding, cur_ptr, &callsite_start);
+		cur_ptr = read_encoded_value (0, lsd_info.call_site_encoding, cur_ptr, &callsite_len);
+		cur_ptr = read_encoded_value (0, lsd_info.call_site_encoding, cur_ptr, &callsite_landing_pad);
+		cur_ptr = read_uleb128 (cur_ptr, &callsite_action);
+
+		//Have we reach the correct frame info yet?
+		if( lsd_info.Start + callsite_start + callsite_len < instruction_ptr ) {
+			//DEBUG BEGIN
+			void * ls = (void*)lsd_info.Start;
+			void * cs = (void*)callsite_start;
+			void * cl = (void*)callsite_len;
+			void * bp = (void*)lsd_info.Start + callsite_start;
+			void * ep = (void*)lsd_info.Start + callsite_start + callsite_len;
+			void * ip = (void*)instruction_ptr;
+			printf("\nfound %p - %p (%p, %p, %p), looking for %p\n", bp, ep, ls, cs, cl, ip);
+			//DEBUG END
+			continue;
+		}
+		
+		//Have we gone too far
+		if( lsd_info.Start + callsite_start > instruction_ptr ) {
+			printf(" gone too far");
+			break;
+		}
+
+		//Something to do?
+		if( callsite_landing_pad ) {
+			//Which phase are we in
+			if (actions & _UA_SEARCH_PHASE) {
+				//Search phase, this means we probably found a potential handler and must check if it is a match
+
+				//If we have arbitrarily decided that 0 means nothing to do and 1 means there is a potential handler
+				//This doesn't seem to conflict the gcc default behavior
+				if (callsite_action != 0) {
+					//Now we want to run some code to see if the handler matches
+					//This is the tricky part where we want to the power to run arbitrary code
+					//However, generating a new exception table entry and try routine every time 
+					//is way more expansive than we might like
+					//The information we have is :
+					//  - The GR (???)
+					//  - The instruction pointer
+					//  - The instruction pointer info (???)
+					//  - The CFA (???)
+					//  - The BSP (Probably the base stack pointer)
+
+
+					//The current apprach uses one exception table entry per try block
+					_uleb128_t imatcher;
+					//Get the relative offset to the 
+					cur_ptr = read_uleb128 (cur_ptr, &imatcher);
+
+					//Get a function pointer from the relative offset and call it
+					_Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher;					
+					_Unwind_Reason_Code ret = matcher();
+
+					//Based on the return value, check if we matched the exception
+					if( ret == _URC_HANDLER_FOUND) printf(" handler found\n");
+					else printf(" no handler\n");
+					return ret;
+				}
+
+				//This is only a cleanup handler, ignore it
+				printf(" no action");
+			} 
+			else if (actions & _UA_CLEANUP_PHASE) {
+
+				if( (callsite_action != 0) && !(actions & _UA_HANDLER_FRAME) ){
+					//If this is a potential exception handler 
+					//but not the one that matched the exception in the seach phase,
+					//just ignore it
+					goto UNWIND;
+				}
+
+				//We need to run some clean-up or a handler
+				//These statment do the right thing but I don't know any specifics at all
+				_Unwind_SetGR( context, __builtin_eh_return_data_regno(0), (_Unwind_Ptr) unwind_exception );
+				_Unwind_SetGR( context, __builtin_eh_return_data_regno(1), 0 );
+
+				//I assume this sets the instruction pointer to the adress of the landing pad
+				//It doesn't actually set it, it only state the value that needs to be set once we return _URC_INSTALL_CONTEXT
+				_Unwind_SetIP( context, lsd_info.LPStart + callsite_landing_pad );
+
+				//DEBUG
+				printf(" action\n");
+
+				//Return have some action to run
+				return _URC_INSTALL_CONTEXT;
+			}
+		}
+
+		//Nothing to do, move along
+		printf(" no landing pad");
+	}
+	//No handling found
+	printf(" table end reached\n");
+
+	//DEBUG
+	UNWIND:
+	printf(" unwind\n");
+
+	//Keep unwinding the stack
+	return _URC_CONTINUE_UNWIND;
+}
+
+//We need a piece of storage to raise the exception
+struct _Unwind_Exception this_exception_storage;
+
+//Function needed by force unwind
+//It basically says to unwind the whole stack and then exit when we reach the end of the stack
+static _Unwind_Reason_Code _Stop_Fn(	
+	int version, 
+	_Unwind_Action actions, 
+	_Unwind_Exception_Class exceptionClass, 
+	struct _Unwind_Exception * unwind_exception, 
+	struct _Unwind_Context * context, 
+	void * some_param
+) {
+	if( actions & _UA_END_OF_STACK  ) exit(1);
+	if( actions & _UA_CLEANUP_PHASE ) return _URC_NO_REASON;
+
+	return _URC_FATAL_PHASE2_ERROR;
+}
+
+//Example throw routine
+void throw( int val ) {
+	//Store the current exception
+	this_exception = val;
+
+	//DEBUG
+	printf("Throwing exception %d\n", this_exception);
+
+	//Call stdlibc to raise the exception
+	_Unwind_Reason_Code ret = _Unwind_RaiseException( &this_exception_storage );
+
+	//If we reach here it means something happened
+	//For resumption to work we need to find a way to return back to here
+	//Most of them will probably boil down to setting a global flag and making the phase 1 either stop or fail.
+	//Causing an error on purpose may help avoiding unnecessary work but it might have some weird side effects.
+	//If we just pretend no handler was found that would work but may be expensive for no reason since we will always
+	//search the whole stack
+
+	if( ret == _URC_END_OF_STACK ) {
+		//No proper handler was found
+		//This can be handled in several way
+		//C++ calls std::terminate
+		//Here we force unwind the stack, basically raising a cancellation
+		printf("Uncaught exception %p\n", &this_exception_storage);
+		
+		ret = _Unwind_ForcedUnwind( &this_exception_storage, _Stop_Fn, (void*)0x22 );
+		printf("UNWIND ERROR %d after force unwind\n", ret);
+		abort();
+	}
+
+	//We did not simply reach the end of the stack without finding a handler,
+	//Something wen't wrong
+	printf("UNWIND ERROR %d after raise exception\n", ret);
+	abort();
+}
Index: doc/working/exception/impl/except.h
===================================================================
--- doc/working/exception/impl/except.h	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
+++ doc/working/exception/impl/except.h	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
@@ -0,0 +1,3 @@
+#include <unwind.h>
+
+void throw( int val );
Index: doc/working/exception/impl/lsda.h
===================================================================
--- doc/working/exception/impl/lsda.h	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
+++ doc/working/exception/impl/lsda.h	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
@@ -0,0 +1,262 @@
+//This code was stolen from gcc to read exception tables
+
+
+/* If using C++, references to abort have to be qualified with std::.  */
+#if __cplusplus
+#define __gxx_abort std::abort
+#else
+#define __gxx_abort abort
+#endif
+
+/* Pointer encodings, from dwarf2.h.  */
+#define DW_EH_PE_absptr         0x00
+#define DW_EH_PE_omit           0xff
+
+#define DW_EH_PE_uleb128        0x01
+#define DW_EH_PE_udata2         0x02
+#define DW_EH_PE_udata4         0x03
+#define DW_EH_PE_udata8         0x04
+#define DW_EH_PE_sleb128        0x09
+#define DW_EH_PE_sdata2         0x0A
+#define DW_EH_PE_sdata4         0x0B
+#define DW_EH_PE_sdata8         0x0C
+#define DW_EH_PE_signed         0x08
+
+#define DW_EH_PE_pcrel          0x10
+#define DW_EH_PE_textrel        0x20
+#define DW_EH_PE_datarel        0x30
+#define DW_EH_PE_funcrel        0x40
+#define DW_EH_PE_aligned        0x50
+
+#define DW_EH_PE_indirect	0x80
+
+
+
+int handler_found = 0;
+
+/* Given an encoding, return the number of bytes the format occupies.
+This is only defined for fixed-size encodings, and so does not
+include leb128.  */
+static unsigned int size_of_encoded_value (unsigned char encoding) __attribute__ ((unused));
+
+static unsigned int size_of_encoded_value (unsigned char encoding)
+{
+	if (encoding == DW_EH_PE_omit) return 0;
+
+	switch (encoding & 0x07) {
+		case DW_EH_PE_absptr: return sizeof (void *);
+		case DW_EH_PE_udata2: return 2;
+		case DW_EH_PE_udata4: return 4;
+		case DW_EH_PE_udata8: return 8;
+	}
+	__gxx_abort ();
+}
+
+/* Given an encoding and an _Unwind_Context, return the base to which
+the encoding is relative.  This base may then be passed to
+read_encoded_value_with_base for use when the _Unwind_Context is
+not available.  */
+static _Unwind_Ptr base_of_encoded_value (unsigned char encoding, struct _Unwind_Context *context)
+{
+	if (encoding == DW_EH_PE_omit) return 0;
+
+	switch (encoding & 0x70) {
+		case DW_EH_PE_absptr:
+		case DW_EH_PE_pcrel:
+		case DW_EH_PE_aligned:
+			return 0;
+		case DW_EH_PE_textrel:
+			return _Unwind_GetTextRelBase (context);
+		case DW_EH_PE_datarel:
+			return _Unwind_GetDataRelBase (context);
+		case DW_EH_PE_funcrel:
+			return _Unwind_GetRegionStart (context);
+	}
+	__gxx_abort ();
+}
+
+/* Read an unsigned leb128 value from P, store the value in VAL, return
+P incremented past the value.  We assume that a word is large enough to
+hold any value so encoded; if it is smaller than a pointer on some target,
+pointers should not be leb128 encoded on that target.  */
+static const unsigned char * read_uleb128 (const unsigned char *p, _uleb128_t *val)
+{
+	unsigned int shift = 0;
+	unsigned char byte;
+	_uleb128_t result;
+
+	result = 0;
+	do
+	{
+		byte = *p++;
+		result |= ((_uleb128_t)byte & 0x7f) << shift;
+		shift += 7;
+	}
+	while (byte & 0x80);
+
+	*val = result;
+	return p;
+}
+
+/* Similar, but read a signed leb128 value.  */
+static const unsigned char * read_sleb128 (const unsigned char *p, _sleb128_t *val)
+{
+	unsigned int shift = 0;
+	unsigned char byte;
+	_uleb128_t result;
+
+	result = 0;
+	do
+	{
+		byte = *p++;
+		result |= ((_uleb128_t)byte & 0x7f) << shift;
+		shift += 7;
+	}
+	while (byte & 0x80);
+
+	/* Sign-extend a negative value.  */
+	if (shift < 8 * sizeof(result) && (byte & 0x40) != 0) result |= -(((_uleb128_t)1L) << shift);
+
+	*val = (_sleb128_t) result;
+	return p;
+}
+
+/* Load an encoded value from memory at P.  The value is returned in VAL;
+The function returns P incremented past the value.  BASE is as given
+by base_of_encoded_value for this encoding in the appropriate context.  */
+
+static const unsigned char * read_encoded_value_with_base (unsigned char encoding, _Unwind_Ptr base, const unsigned char *p, _Unwind_Ptr *val)
+{
+	union unaligned
+	{
+		void *ptr;
+		unsigned u2 __attribute__ ((mode (HI)));
+		unsigned u4 __attribute__ ((mode (SI)));
+		unsigned u8 __attribute__ ((mode (DI)));
+		signed s2 __attribute__ ((mode (HI)));
+		signed s4 __attribute__ ((mode (SI)));
+		signed s8 __attribute__ ((mode (DI)));
+	} __attribute__((__packed__));
+
+	const union unaligned *u = (const union unaligned *) p;
+	_Unwind_Internal_Ptr result;
+
+	if (encoding == DW_EH_PE_aligned)
+	{
+		_Unwind_Internal_Ptr a = (_Unwind_Internal_Ptr) p;
+		a = (a + sizeof (void *) - 1) & - sizeof(void *);
+		result = *(_Unwind_Internal_Ptr *) a;
+		p = (const unsigned char *) (_Unwind_Internal_Ptr) (a + sizeof (void *));
+	}
+	else
+	{
+		switch (encoding & 0x0f)
+		{
+			case DW_EH_PE_absptr:
+				result = (_Unwind_Internal_Ptr) u->ptr;
+				p += sizeof (void *);
+				break;
+			case DW_EH_PE_uleb128:
+			{
+				_uleb128_t tmp;
+				p = read_uleb128 (p, &tmp);
+				result = (_Unwind_Internal_Ptr) tmp;
+			}
+			break;
+
+			case DW_EH_PE_sleb128:
+			{
+				_sleb128_t tmp;
+				p = read_sleb128 (p, &tmp);
+				result = (_Unwind_Internal_Ptr) tmp;
+			}
+			break;
+
+			case DW_EH_PE_udata2:
+				result = u->u2;
+				p += 2;
+				break;
+			case DW_EH_PE_udata4:
+				result = u->u4;
+				p += 4;
+				break;
+			case DW_EH_PE_udata8:
+				result = u->u8;
+				p += 8;
+				break;
+			case DW_EH_PE_sdata2:
+				result = u->s2;
+				p += 2;
+				break;
+			case DW_EH_PE_sdata4:
+				result = u->s4;
+				p += 4;
+				break;
+			case DW_EH_PE_sdata8:
+				result = u->s8;
+				p += 8;
+				break;
+			default:
+				__gxx_abort();
+		}
+
+		if (result != 0)
+		{
+			result += ((encoding & 0x70) == DW_EH_PE_pcrel ? (_Unwind_Internal_Ptr) u : base);
+			
+			if (encoding & DW_EH_PE_indirect) result = *(_Unwind_Internal_Ptr *) result;
+		}
+	}
+
+	*val = result;
+	return p;
+}
+
+/* Like read_encoded_value_with_base, but get the base from the context
+rather than providing it directly.  */
+static inline const unsigned char * read_encoded_value (struct _Unwind_Context *context, unsigned char encoding, const unsigned char *p, _Unwind_Ptr *val)
+{
+	return read_encoded_value_with_base (encoding, base_of_encoded_value (encoding, context), p, val);
+}
+
+typedef struct
+{
+	_Unwind_Ptr Start;
+	_Unwind_Ptr LPStart;
+	_Unwind_Ptr ttype_base;
+	const unsigned char *TType;
+	const unsigned char *action_table;
+	unsigned char ttype_encoding;
+	unsigned char call_site_encoding;
+} lsda_header_info;
+
+static const unsigned char * parse_lsda_header (struct _Unwind_Context *context, const unsigned char *p, lsda_header_info *info)
+{
+	_uleb128_t tmp;
+	unsigned char lpstart_encoding;
+
+	info->Start = (context ? _Unwind_GetRegionStart (context) : 0);
+
+	/* Find @LPStart, the base to which landing pad offsets are relative.  */
+	lpstart_encoding = *p++;
+	if (lpstart_encoding != DW_EH_PE_omit) p = read_encoded_value (context, lpstart_encoding, p, &info->LPStart);
+
+	else info->LPStart = info->Start;
+
+	/* Find @TType, the base of the handler and exception spec type data.  */
+	info->ttype_encoding = *p++;
+	if (info->ttype_encoding != DW_EH_PE_omit)
+	{
+		p = read_uleb128 (p, &tmp);
+		info->TType = p + tmp;
+	}
+	else info->TType = 0;
+
+	/* The encoding and length of the call-site table; the action table
+	immediately follows.  */
+	info->call_site_encoding = *p++;
+	p = read_uleb128 (p, &tmp);
+	info->action_table = p + tmp;
+
+	return p;
+}
Index: doc/working/exception/impl/main.c
===================================================================
--- doc/working/exception/impl/main.c	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
+++ doc/working/exception/impl/main.c	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
@@ -0,0 +1,134 @@
+#include <stdio.h>
+#include "except.h"
+
+#define EXCEPTION 2
+
+struct type_raii_t {
+	char * msg;
+};
+
+//Dtor function to test clean up routines
+void dtor( struct type_raii_t * this ) {
+	printf("%s\n", this->msg);
+}
+
+//Type macro use to make scope unwinding easier to see.
+#define raii_t __attribute__(( cleanup(dtor) )) struct type_raii_t
+
+//Leaf functions that raises exception
+void bar() {
+	raii_t a = { "Bar dtor" };
+
+	throw( EXCEPTION );
+}
+
+//Matcher function which will check if the exception was correctly caught
+extern int this_exception;
+_Unwind_Reason_Code foo_try_match() {
+	return this_exception == 3 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
+}
+
+//Try statements are hoisted out see comments for details
+//With this could probably be unique and simply linked from
+//libcfa but there is one problem left, see the exception table 
+//for details
+void try( void (*try_block)(), void (*catch_block)() )
+{
+	//Setup statments
+	//These 2 statments won't actually result in any code,
+	//they only setup global tables.
+	//However, they clobber gcc cancellation support from gcc.
+	//We can replace the personality routine but replacing the exception
+	//table gcc generates is not really doable, it generates labels based
+	//on how the assembly works.
+	//Setup the personality routine
+	asm volatile (".cfi_personality 0x3,__gcfa_personality_v0");
+	//Setup the exception table
+	asm volatile (".cfi_lsda 0x3, .LLSDACFA2");
+
+	//Label which defines the start of the area for which the handler is setup
+	asm volatile (".TRYSTART:");
+
+	//The actual statements of the try blocks
+	try_block();
+
+	//asm statement to prevent deadcode removal
+	asm volatile goto ("" : : : : CATCH );
+
+	//Normal return
+	return;
+
+	//Exceptionnal path
+	CATCH : __attribute__(( unused ));
+	//Label which defines the end of the area for which the handler is setup
+	asm volatile (".TRYEND:");
+	//Label which defines the start of the exception landing pad
+	//basically what will be called when the exception is caught
+	//Note, if multiple handlers are given, the multiplexing should be done
+	//by the generated code, not the exception runtime
+	asm volatile (".CATCH:");
+
+	//Exception handler
+	catch_block();
+}
+
+//Exception table data we need to generate
+//While this is almost generic, the custom data refers to
+//foo_try_match try match, which is no way generic
+//Some more works need to be done if we want to have a single 
+//call to the try routine
+asm (
+	//HEADER
+	".LFECFA1:\n"
+	"	.globl	__gcfa_personality_v0\n"
+	"	.section	.gcc_except_table,\"a\",@progbits\n"
+	".LLSDACFA2:\n"							//TABLE header
+	"	.byte	0xff\n"
+	"	.byte	0xff\n"
+	"	.byte	0x1\n"
+	"	.uleb128 .LLSDACSECFA2-.LLSDACSBCFA2\n"		//BODY length
+	//Body uses language specific data and therefore could be modified arbitrarily
+	".LLSDACSBCFA2:\n"						//BODY start
+	"	.uleb128 .TRYSTART-try\n"				//Handled area start  (relative to start of function)
+	"	.uleb128 .TRYEND-.TRYSTART\n"				//Handled area length
+	"	.uleb128 .CATCH-try\n"				//Hanlder landing pad adress  (relative to start of function)
+	"	.uleb128 1\n"						//Action code, gcc seems to use always 0
+	//Beyond this point we don't match gcc data'
+	"	.uleb128 foo_try_match-try\n"			//Handler routine to check if the exception is matched
+	".LLSDACSECFA2:\n"						//BODY end
+	"	.text\n"							//TABLE footer
+	"	.size	try, .-try\n"
+	"	.ident	\"GCC: (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901\"\n"
+	"	.section	.note.GNU-stack,\"x\",@progbits\n"
+);
+
+void foo() {
+	raii_t a = { "Foo dtor" };
+
+	//Since try will clobber the gcc exception table assembly,
+	//We need to nest this to have gcc regenerate the data
+	void foo_try_block() {
+		raii_t b = { "Foo try dtor" };
+
+		bar();
+
+		printf("Called bar successfully\n");
+	}
+
+	void foo_catch_block() {
+		printf("Exception caught\n");
+	}
+
+	//Actual call to the try block
+	try( foo_try_block, foo_catch_block );
+
+	printf( "Foo exited normally\n" );
+}
+
+int main() {
+	raii_t a = { "Main dtor" };
+
+	foo();
+
+	printf("End of program reached\n");
+}
Index: doc/working/exception/impl/main.cfa
===================================================================
--- doc/working/exception/impl/main.cfa	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
+++ doc/working/exception/impl/main.cfa	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include "except.h"
+
+struct raii_t {
+	char * msg;
+};
+
+void ^?{}( type_raii_t * this ) {
+	printf("%s\n", this->msg);
+}
+
+void bar() {
+	raii_t a = { "Bar dtor" };
+
+	throw( 3 );
+}
+
+void foo() {
+	raii_t a = { "Foo dtor" };
+
+	try {
+		raii_t b = { "Foo try dtor" };
+
+		bar();
+
+		printf("Called bar successfully\n");
+	}
+	catch( 2 ) {
+		printf("Exception caught\n");
+	}
+
+	printf( "Foo exited normally\n" );
+}
+
+int main() {
+	raii_t a = { "Main dtor" };
+
+	foo();
+
+	printf("End of program reached\n");
+}
Index: c/working/exception/lsda.h
===================================================================
--- doc/working/exception/lsda.h	(revision 2c9ebabd500b086aeb45d01caed3a928fad5b3c2)
+++ 	(revision )
@@ -1,262 +1,0 @@
-//This code was stolen from gcc to read exception tables
-
-
-/* If using C++, references to abort have to be qualified with std::.  */
-#if __cplusplus
-#define __gxx_abort std::abort
-#else
-#define __gxx_abort abort
-#endif
-
-/* Pointer encodings, from dwarf2.h.  */
-#define DW_EH_PE_absptr         0x00
-#define DW_EH_PE_omit           0xff
-
-#define DW_EH_PE_uleb128        0x01
-#define DW_EH_PE_udata2         0x02
-#define DW_EH_PE_udata4         0x03
-#define DW_EH_PE_udata8         0x04
-#define DW_EH_PE_sleb128        0x09
-#define DW_EH_PE_sdata2         0x0A
-#define DW_EH_PE_sdata4         0x0B
-#define DW_EH_PE_sdata8         0x0C
-#define DW_EH_PE_signed         0x08
-
-#define DW_EH_PE_pcrel          0x10
-#define DW_EH_PE_textrel        0x20
-#define DW_EH_PE_datarel        0x30
-#define DW_EH_PE_funcrel        0x40
-#define DW_EH_PE_aligned        0x50
-
-#define DW_EH_PE_indirect	0x80
-
-
-
-int handler_found = 0;
-
-/* Given an encoding, return the number of bytes the format occupies.
-This is only defined for fixed-size encodings, and so does not
-include leb128.  */
-static unsigned int size_of_encoded_value (unsigned char encoding) __attribute__ ((unused));
-
-static unsigned int size_of_encoded_value (unsigned char encoding)
-{
-	if (encoding == DW_EH_PE_omit) return 0;
-
-	switch (encoding & 0x07) {
-		case DW_EH_PE_absptr: return sizeof (void *);
-		case DW_EH_PE_udata2: return 2;
-		case DW_EH_PE_udata4: return 4;
-		case DW_EH_PE_udata8: return 8;
-	}
-	__gxx_abort ();
-}
-
-/* Given an encoding and an _Unwind_Context, return the base to which
-the encoding is relative.  This base may then be passed to
-read_encoded_value_with_base for use when the _Unwind_Context is
-not available.  */
-static _Unwind_Ptr base_of_encoded_value (unsigned char encoding, struct _Unwind_Context *context)
-{
-	if (encoding == DW_EH_PE_omit) return 0;
-
-	switch (encoding & 0x70) {
-		case DW_EH_PE_absptr:
-		case DW_EH_PE_pcrel:
-		case DW_EH_PE_aligned:
-			return 0;
-		case DW_EH_PE_textrel:
-			return _Unwind_GetTextRelBase (context);
-		case DW_EH_PE_datarel:
-			return _Unwind_GetDataRelBase (context);
-		case DW_EH_PE_funcrel:
-			return _Unwind_GetRegionStart (context);
-	}
-	__gxx_abort ();
-}
-
-/* Read an unsigned leb128 value from P, store the value in VAL, return
-P incremented past the value.  We assume that a word is large enough to
-hold any value so encoded; if it is smaller than a pointer on some target,
-pointers should not be leb128 encoded on that target.  */
-static const unsigned char * read_uleb128 (const unsigned char *p, _uleb128_t *val)
-{
-	unsigned int shift = 0;
-	unsigned char byte;
-	_uleb128_t result;
-
-	result = 0;
-	do
-	{
-		byte = *p++;
-		result |= ((_uleb128_t)byte & 0x7f) << shift;
-		shift += 7;
-	}
-	while (byte & 0x80);
-
-	*val = result;
-	return p;
-}
-
-/* Similar, but read a signed leb128 value.  */
-static const unsigned char * read_sleb128 (const unsigned char *p, _sleb128_t *val)
-{
-	unsigned int shift = 0;
-	unsigned char byte;
-	_uleb128_t result;
-
-	result = 0;
-	do
-	{
-		byte = *p++;
-		result |= ((_uleb128_t)byte & 0x7f) << shift;
-		shift += 7;
-	}
-	while (byte & 0x80);
-
-	/* Sign-extend a negative value.  */
-	if (shift < 8 * sizeof(result) && (byte & 0x40) != 0) result |= -(((_uleb128_t)1L) << shift);
-
-	*val = (_sleb128_t) result;
-	return p;
-}
-
-/* Load an encoded value from memory at P.  The value is returned in VAL;
-The function returns P incremented past the value.  BASE is as given
-by base_of_encoded_value for this encoding in the appropriate context.  */
-
-static const unsigned char * read_encoded_value_with_base (unsigned char encoding, _Unwind_Ptr base, const unsigned char *p, _Unwind_Ptr *val)
-{
-	union unaligned
-	{
-		void *ptr;
-		unsigned u2 __attribute__ ((mode (HI)));
-		unsigned u4 __attribute__ ((mode (SI)));
-		unsigned u8 __attribute__ ((mode (DI)));
-		signed s2 __attribute__ ((mode (HI)));
-		signed s4 __attribute__ ((mode (SI)));
-		signed s8 __attribute__ ((mode (DI)));
-	} __attribute__((__packed__));
-
-	const union unaligned *u = (const union unaligned *) p;
-	_Unwind_Internal_Ptr result;
-
-	if (encoding == DW_EH_PE_aligned)
-	{
-		_Unwind_Internal_Ptr a = (_Unwind_Internal_Ptr) p;
-		a = (a + sizeof (void *) - 1) & - sizeof(void *);
-		result = *(_Unwind_Internal_Ptr *) a;
-		p = (const unsigned char *) (_Unwind_Internal_Ptr) (a + sizeof (void *));
-	}
-	else
-	{
-		switch (encoding & 0x0f)
-		{
-			case DW_EH_PE_absptr:
-				result = (_Unwind_Internal_Ptr) u->ptr;
-				p += sizeof (void *);
-				break;
-			case DW_EH_PE_uleb128:
-			{
-				_uleb128_t tmp;
-				p = read_uleb128 (p, &tmp);
-				result = (_Unwind_Internal_Ptr) tmp;
-			}
-			break;
-
-			case DW_EH_PE_sleb128:
-			{
-				_sleb128_t tmp;
-				p = read_sleb128 (p, &tmp);
-				result = (_Unwind_Internal_Ptr) tmp;
-			}
-			break;
-
-			case DW_EH_PE_udata2:
-				result = u->u2;
-				p += 2;
-				break;
-			case DW_EH_PE_udata4:
-				result = u->u4;
-				p += 4;
-				break;
-			case DW_EH_PE_udata8:
-				result = u->u8;
-				p += 8;
-				break;
-			case DW_EH_PE_sdata2:
-				result = u->s2;
-				p += 2;
-				break;
-			case DW_EH_PE_sdata4:
-				result = u->s4;
-				p += 4;
-				break;
-			case DW_EH_PE_sdata8:
-				result = u->s8;
-				p += 8;
-				break;
-			default:
-				__gxx_abort();
-		}
-
-		if (result != 0)
-		{
-			result += ((encoding & 0x70) == DW_EH_PE_pcrel ? (_Unwind_Internal_Ptr) u : base);
-			
-			if (encoding & DW_EH_PE_indirect) result = *(_Unwind_Internal_Ptr *) result;
-		}
-	}
-
-	*val = result;
-	return p;
-}
-
-/* Like read_encoded_value_with_base, but get the base from the context
-rather than providing it directly.  */
-static inline const unsigned char * read_encoded_value (struct _Unwind_Context *context, unsigned char encoding, const unsigned char *p, _Unwind_Ptr *val)
-{
-	return read_encoded_value_with_base (encoding, base_of_encoded_value (encoding, context), p, val);
-}
-
-typedef struct
-{
-	_Unwind_Ptr Start;
-	_Unwind_Ptr LPStart;
-	_Unwind_Ptr ttype_base;
-	const unsigned char *TType;
-	const unsigned char *action_table;
-	unsigned char ttype_encoding;
-	unsigned char call_site_encoding;
-} lsda_header_info;
-
-static const unsigned char * parse_lsda_header (struct _Unwind_Context *context, const unsigned char *p, lsda_header_info *info)
-{
-	_uleb128_t tmp;
-	unsigned char lpstart_encoding;
-
-	info->Start = (context ? _Unwind_GetRegionStart (context) : 0);
-
-	/* Find @LPStart, the base to which landing pad offsets are relative.  */
-	lpstart_encoding = *p++;
-	if (lpstart_encoding != DW_EH_PE_omit) p = read_encoded_value (context, lpstart_encoding, p, &info->LPStart);
-
-	else info->LPStart = info->Start;
-
-	/* Find @TType, the base of the handler and exception spec type data.  */
-	info->ttype_encoding = *p++;
-	if (info->ttype_encoding != DW_EH_PE_omit)
-	{
-		p = read_uleb128 (p, &tmp);
-		info->TType = p + tmp;
-	}
-	else info->TType = 0;
-
-	/* The encoding and length of the call-site table; the action table
-	immediately follows.  */
-	info->call_site_encoding = *p++;
-	p = read_uleb128 (p, &tmp);
-	info->action_table = p + tmp;
-
-	return p;
-}
Index: c/working/exception/main.c
===================================================================
--- doc/working/exception/main.c	(revision 2c9ebabd500b086aeb45d01caed3a928fad5b3c2)
+++ 	(revision )
@@ -1,134 +1,0 @@
-#include <stdio.h>
-#include "except.h"
-
-#define EXCEPTION 2
-
-struct type_raii_t {
-	char * msg;
-};
-
-//Dtor function to test clean up routines
-void dtor( struct type_raii_t * this ) {
-	printf("%s\n", this->msg);
-}
-
-//Type macro use to make scope unwinding easier to see.
-#define raii_t __attribute__(( cleanup(dtor) )) struct type_raii_t
-
-//Leaf functions that raises exception
-void bar() {
-	raii_t a = { "Bar dtor" };
-
-	throw( EXCEPTION );
-}
-
-//Matcher function which will check if the exception was correctly caught
-extern int this_exception;
-_Unwind_Reason_Code foo_try_match() {
-	return this_exception == 2 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
-}
-
-//Try statements are hoisted out see comments for details
-//With this could probably be unique and simply linked from
-//libcfa but there is one problem left, see the exception table 
-//for details
-void try( void (*try_block)(), void (*catch_block)() )
-{
-	//Setup statments
-	//These 2 statments won't actually result in any code,
-	//they only setup global tables.
-	//However, they clobber gcc cancellation support from gcc.
-	//We can replace the personality routine but replacing the exception
-	//table gcc generates is not really doable, it generates labels based
-	//on how the assembly works.
-	//Setup the personality routine
-	asm volatile (".cfi_personality 0x3,__gcfa_personality_v0");
-	//Setup the exception table
-	asm volatile (".cfi_lsda 0x3, .LLSDACFA2");
-
-	//Label which defines the start of the area for which the handler is setup
-	asm volatile (".TRYSTART:");
-
-	//The actual statements of the try blocks
-	try_block();
-
-	//asm statement to prevent deadcode removal
-	asm volatile goto ("" : : : : CATCH );
-
-	//Normal return
-	return;
-
-	//Exceptionnal path
-	CATCH : __attribute__(( unused ));
-	//Label which defines the end of the area for which the handler is setup
-	asm volatile (".TRYEND:");
-	//Label which defines the start of the exception landing pad
-	//basically what will be called when the exception is caught
-	//Note, if multiple handlers are given, the multiplexing should be done
-	//by the generated code, not the exception runtime
-	asm volatile (".CATCH:");
-
-	//Exception handler
-	catch_block();
-}
-
-//Exception table data we need to generate
-//While this is almost generic, the custom data refers to
-//foo_try_match try match, which is no way generic
-//Some more works need to be done if we want to have a single 
-//call to the try routine
-asm (
-	//HEADER
-	".LFECFA1:\n"
-	"	.globl	__gcfa_personality_v0\n"
-	"	.section	.gcc_except_table,\"a\",@progbits\n"
-	".LLSDACFA2:\n"							//TABLE header
-	"	.byte	0xff\n"
-	"	.byte	0xff\n"
-	"	.byte	0x1\n"
-	"	.uleb128 .LLSDACSECFA2-.LLSDACSBCFA2\n"		//BODY length
-	//Body uses language specific data and therefore could be modified arbitrarily
-	".LLSDACSBCFA2:\n"						//BODY start
-	"	.uleb128 .TRYSTART-try\n"				//Handled area start  (relative to start of function)
-	"	.uleb128 .TRYEND-.TRYSTART\n"				//Handled area length
-	"	.uleb128 .CATCH-try\n"				//Hanlder landing pad adress  (relative to start of function)
-	"	.uleb128 1\n"						//Action code, gcc seems to use always 0
-	//Beyond this point we don't match gcc data'
-	"	.uleb128 foo_try_match-try\n"			//Handler routine to check if the exception is matched
-	".LLSDACSECFA2:\n"						//BODY end
-	"	.text\n"							//TABLE footer
-	"	.size	try, .-try\n"
-	"	.ident	\"GCC: (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901\"\n"
-	"	.section	.note.GNU-stack,\"x\",@progbits\n"
-);
-
-void foo() {
-	raii_t a = { "Foo dtor" };
-
-	//Since try will clobber the gcc exception table assembly,
-	//We need to nest this to have gcc regenerate the data
-	void foo_try_block() {
-		raii_t b = { "Foo try dtor" };
-
-		bar();
-
-		printf("Called bar successfully\n");
-	}
-
-	void foo_catch_block() {
-		printf("Exception caught\n");
-	}
-
-	//Actual call to the try block
-	try( foo_try_block, foo_catch_block );
-
-	printf( "Foo exited normally\n" );
-}
-
-int main() {
-	raii_t a = { "Main dtor" };
-
-	foo();
-
-	printf("End of program reached\n");
-}
Index: c/working/exception/main.cfa
===================================================================
--- doc/working/exception/main.cfa	(revision 2c9ebabd500b086aeb45d01caed3a928fad5b3c2)
+++ 	(revision )
@@ -1,41 +1,0 @@
-#include <stdio.h>
-#include "except.h"
-
-struct raii_t {
-	char * msg;
-};
-
-void ^?{}( type_raii_t * this ) {
-	printf("%s\n", this->msg);
-}
-
-void bar() {
-	raii_t a = { "Bar dtor" };
-
-	throw( 3 );
-}
-
-void foo() {
-	raii_t a = { "Foo dtor" };
-
-	try {
-		raii_t b = { "Foo try dtor" };
-
-		bar();
-
-		printf("Called bar successfully\n");
-	}
-	catch( 2 ) {
-		printf("Exception caught\n");
-	}
-
-	printf( "Foo exited normally\n" );
-}
-
-int main() {
-	raii_t a = { "Main dtor" };
-
-	foo();
-
-	printf("End of program reached\n");
-}
Index: src/InitTweak/FixInit.cc
===================================================================
--- src/InitTweak/FixInit.cc	(revision 2c9ebabd500b086aeb45d01caed3a928fad5b3c2)
+++ src/InitTweak/FixInit.cc	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
@@ -896,7 +896,10 @@
 			Parent::visit( compoundStmt );
 
-			// add destructors for the current scope that we're exiting
+			// add destructors for the current scope that we're exiting, unless the last statement is a return, which
+			// causes unreachable code warnings
 			std::list< Statement * > & statements = compoundStmt->get_kids();
-			insertDtors( reverseDeclOrder.front().begin(), reverseDeclOrder.front().end(), back_inserter( statements ) );
+			if ( ! statements.empty() && ! dynamic_cast< ReturnStmt * >( statements.back() ) ) {
+				insertDtors( reverseDeclOrder.front().begin(), reverseDeclOrder.front().end(), back_inserter( statements ) );
+			}
 			reverseDeclOrder.pop_front();
 		}
Index: src/SymTab/Validate.cc
===================================================================
--- src/SymTab/Validate.cc	(revision 2c9ebabd500b086aeb45d01caed3a928fad5b3c2)
+++ src/SymTab/Validate.cc	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
@@ -208,4 +208,12 @@
 	};
 
+	/// ensure that generic types have the correct number of type arguments
+	class ValidateGenericParameters : public Visitor {
+	public:
+		typedef Visitor Parent;
+		virtual void visit( StructInstType * inst ) final override;
+		virtual void visit( UnionInstType * inst ) final override;
+	};
+
 	class ArrayLength : public Visitor {
 	public:
@@ -235,9 +243,11 @@
 		Pass3 pass3( 0 );
 		CompoundLiteral compoundliteral;
-
-		HoistStruct::hoistStruct( translationUnit );
+		ValidateGenericParameters genericParams;
+
 		EliminateTypedef::eliminateTypedef( translationUnit );
+		HoistStruct::hoistStruct( translationUnit ); // must happen after EliminateTypedef, so that aggregate typedefs occur in the correct order
 		ReturnTypeFixer::fix( translationUnit ); // must happen before autogen
 		acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions
+		acceptAll( translationUnit, genericParams );  // check as early as possible - can't happen before LinkReferenceToTypes
 		acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist
 		VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
@@ -829,4 +839,24 @@
 	}
 
+	template< typename Aggr >
+	void validateGeneric( Aggr * inst ) {
+		std::list< TypeDecl * > * params = inst->get_baseParameters();
+		if ( params != NULL ) {
+			std::list< Expression * > & args = inst->get_parameters();
+			if ( args.size() < params->size() ) throw SemanticError( "Too few type arguments in generic type ", inst );
+			if ( args.size() > params->size() ) throw SemanticError( "Too many type arguments in generic type ", inst );
+		}
+	}
+
+	void ValidateGenericParameters::visit( StructInstType * inst ) {
+		validateGeneric( inst );
+		Parent::visit( inst );
+	}
+
+	void ValidateGenericParameters::visit( UnionInstType * inst ) {
+		validateGeneric( inst );
+		Parent::visit( inst );
+	}
+
 	DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) {
 		storageClasses = objectDecl->get_storageClasses();
Index: src/libcfa/gmp
===================================================================
--- src/libcfa/gmp	(revision 2c9ebabd500b086aeb45d01caed3a928fad5b3c2)
+++ src/libcfa/gmp	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
@@ -10,6 +10,6 @@
 // Created On       : Tue Apr 19 08:43:43 2016
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Sun May 14 23:47:36 2017
-// Update Count     : 9
+// Last Modified On : Mon May 22 08:32:39 2017
+// Update Count     : 13
 // 
 
@@ -35,5 +35,5 @@
 Int ?=?( Int * lhs, long int rhs ) { mpz_set_si( lhs->mpz, rhs ); return *lhs; }
 Int ?=?( Int * lhs, unsigned long int rhs ) { mpz_set_ui( lhs->mpz, rhs ); return *lhs; }
-//Int ?=?( Int * lhs, const char * rhs ) { if ( mpq_set_str( lhs->mpz, rhs, 0 ) ) abort(); return *lhs; }
+Int ?=?( Int * lhs, const char * rhs ) { if ( mpz_set_str( lhs->mpz, rhs, 0 ) ) { printf( "invalid string conversion\n" ); abort(); } return *lhs; }
 
 char ?=?( char * lhs, Int rhs ) { char val = mpz_get_si( rhs.mpz ); *lhs = val; return val; }
Index: src/tests/.expect/64/gmp.txt
===================================================================
--- src/tests/.expect/64/gmp.txt	(revision 2c9ebabd500b086aeb45d01caed3a928fad5b3c2)
+++ src/tests/.expect/64/gmp.txt	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
@@ -4,4 +4,5 @@
 conversions
 y:97
+y:12345678901234567890123456789
 y:3
 y:-3
@@ -24,4 +25,5 @@
 z:150000000000000000000
 z:16666666666666666666
+16666666666666666666, 2 16666666666666666666, 2
 x:16666666666666666666 y:2
 
Index: src/tests/gmp.c
===================================================================
--- src/tests/gmp.c	(revision 2c9ebabd500b086aeb45d01caed3a928fad5b3c2)
+++ src/tests/gmp.c	(revision 130991051943d0cf7e8992a92d23eb0d900bec04)
@@ -10,11 +10,11 @@
 // Created On       : Tue Apr 19 08:55:51 2016
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Sun May 14 14:46:50 2017
-// Update Count     : 530
+// Last Modified On : Mon May 22 09:05:09 2017
+// Update Count     : 538
 // 
 
 #include <gmp>
 
-int main() {
+int main( void ) {
 	sout | "constructors" | endl;
 	short int si = 3;
@@ -25,4 +25,6 @@
 	sout | "conversions" | endl;
 	y = 'a';
+	sout | "y:" | y | endl;
+	y = "12345678901234567890123456789";
 	sout | "y:" | y | endl;
 	y = si;
@@ -62,7 +64,7 @@
 	z = x / 3;
 	sout | "z:" | z | endl;
+	sout | div( x, 3 ) | x / 3 | "," | x % 3 | endl;
 	[ x, y ] = div( x, 3 );
 	sout | "x:" | x | "y:" | y | endl;
-//	sout | div( x, 3 ) | x / 3 | "," | x % 3 | endl;
 
 	sout | endl;
@@ -72,7 +74,7 @@
 	fn = (Int){0}; fn1 = fn;							// 1st case
 	sout | (int)0 | fn | endl;
-	fn = (Int){1}; fn2 = fn1; fn1 = fn;					// 2nd case
+	fn = 1; fn2 = fn1; fn1 = fn;						// 2nd case
 	sout | 1 | fn | endl;
-	for ( int i = 2; i <= 200; i += 1 ) {
+	for ( unsigned int i = 2; i <= 200; i += 1 ) {
 		fn = fn1 + fn2; fn2 = fn1; fn1 = fn;			// general case
 		sout | i | fn | endl;
@@ -83,7 +85,7 @@
 	sout | "Factorial Numbers" | endl;
 	Int fact;
-	fact = (Int){1};									// 1st case
+	fact = 1;											// 1st case
 	sout | (int)0 | fact | endl;
-	for ( int i = 1; i <= 40; i += 1 ) {
+	for ( unsigned int i = 1; i <= 40; i += 1 ) {
 		fact = fact * i;								// general case
 		sout | i | fact | endl;
