Index: src/SymTab/Indexer.cc
===================================================================
--- src/SymTab/Indexer.cc	(revision 834d4fc488a7e141443f7b9d7f3f966648fdf1fd)
+++ src/SymTab/Indexer.cc	(revision 9c791ddf2c2ea0de4b5c1338cd0581fa3dfaa4cc)
@@ -526,4 +526,21 @@
 
 		return tables->base.hasIncompatibleCDecl( id, mangleName, scope );
+	}
+
+	bool Indexer::hasCompatibleCDecl( const std::string &id, const std::string &mangleName, unsigned long scope ) const {
+		if ( ! tables ) return false;
+		if ( tables->scope < scope ) return false;
+
+		IdTable::const_iterator decls = tables->idTable.find( id );
+		if ( decls != tables->idTable.end() ) {
+			const MangleTable &mangleTable = decls->second;
+			for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) {
+				// check for C decls with the same name, skipping
+				// those with an incompatible type (by mangleName)
+				if ( decl->second->get_linkage() == LinkageSpec::C && decl->first == mangleName ) return true;
+			}
+		}
+
+		return tables->base.hasCompatibleCDecl( id, mangleName, scope );
 	}
 
@@ -616,18 +633,28 @@
 		} // if
 
+		// this ensures that no two declarations with the same unmangled name at the same scope both have C linkage
+		if ( decl->get_linkage() == LinkageSpec::C ) {
+			// NOTE this is broken in Richard's original code in such a way that it never triggers (it
+			// doesn't check decls that have the same manglename, and all C-linkage decls are defined to
+			// have their name as their manglename, hence the error can never trigger).
+			// The code here is closer to correct, but name mangling would have to be completely
+			// isomorphic to C type-compatibility, which it may not be.
+			if ( hasIncompatibleCDecl( name, mangleName, scope ) ) {
+				throw SemanticError( "conflicting overload of C function ", decl );
+			}
+		} else {
+			// Check that a Cforall declaration doesn't overload any C declaration
+			if ( hasCompatibleCDecl( name, mangleName, scope ) ) {
+				throw SemanticError( "Cforall declaration hides C function ", decl );
+			}
+		}
+
+		// Skip repeat declarations of the same identifier
 		DeclarationWithType *existing = lookupIdAtScope( name, mangleName, scope );
-		if ( ! existing || ! addedIdConflicts( existing, decl ) ) {
-			// this ensures that no two declarations with the same unmangled name at the same scope both have C linkage
-			if ( decl->get_linkage() == LinkageSpec::C && hasIncompatibleCDecl( name, mangleName, scope ) ) {
-				throw SemanticError( "invalid overload of C function ", decl );
-			} // NOTE this is broken in Richard's original code in such a way that it never triggers (it
-			  // doesn't check decls that have the same manglename, and all C-linkage decls are defined to
-			  // have their name as their manglename, hence the error can never trigger).
-			  // The code here is closer to correct, but name mangling would have to be completely
-			  // isomorphic to C type-compatibility, which it may not be.
-
-			tables->idTable[ name ][ mangleName ] = decl;
-			++tables->size;
-		}
+		if ( existing && addedIdConflicts( existing, decl ) ) return;
+
+		// add to indexer
+		tables->idTable[ name ][ mangleName ] = decl;
+		++tables->size;
 	}
 
Index: src/SymTab/Indexer.h
===================================================================
--- src/SymTab/Indexer.h	(revision 834d4fc488a7e141443f7b9d7f3f966648fdf1fd)
+++ src/SymTab/Indexer.h	(revision 9c791ddf2c2ea0de4b5c1338cd0581fa3dfaa4cc)
@@ -100,4 +100,6 @@
 		/// returns true if there exists a declaration with C linkage and the given name with a different mangled name
 		bool hasIncompatibleCDecl( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
+		/// returns true if there exists a declaration with C linkage and the given name with the same mangled name
+		bool hasCompatibleCDecl( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
 		// equivalents to lookup functions that only look at tables at scope `scope` (which should be >= tables->scope)
 		NamedTypeDecl *lookupTypeAtScope( const std::string &id, unsigned long scope ) const;
Index: src/SymTab/Mangler.cc
===================================================================
--- src/SymTab/Mangler.cc	(revision 834d4fc488a7e141443f7b9d7f3f966648fdf1fd)
+++ src/SymTab/Mangler.cc	(revision 9c791ddf2c2ea0de4b5c1338cd0581fa3dfaa4cc)
@@ -282,7 +282,8 @@
 			mangleName << "V";
 		} // if
-		if ( type->get_isRestrict() ) {
-			mangleName << "R";
-		} // if
+		// Removed due to restrict not affecting function compatibility in GCC
+//		if ( type->get_isRestrict() ) {
+//			mangleName << "R";
+//		} // if
 		if ( type->get_isLvalue() ) {
 			mangleName << "L";
Index: src/libcfa/math
===================================================================
--- src/libcfa/math	(revision 834d4fc488a7e141443f7b9d7f3f966648fdf1fd)
+++ src/libcfa/math	(revision 9c791ddf2c2ea0de4b5c1338cd0581fa3dfaa4cc)
@@ -184,5 +184,5 @@
 
 float atan2( float, float );
-double atan2( double, double );
+// extern "C" { double atan2( double, double ); }
 long double atan2( long double, long double );
 
Index: src/libcfa/math.c
===================================================================
--- src/libcfa/math.c	(revision 834d4fc488a7e141443f7b9d7f3f966648fdf1fd)
+++ src/libcfa/math.c	(revision 9c791ddf2c2ea0de4b5c1338cd0581fa3dfaa4cc)
@@ -23,5 +23,4 @@
 long double fabs( long double x ) { return fabsl( x ); }
 float cabs( float _Complex x ) { return cabsf( x ); }
-double cabs( double _Complex x ) { return cabs( x ); }
 long double cabs( long double _Complex x ) { return cabsl( x ); }
 
@@ -159,5 +158,4 @@
 
 float atan2( float x, float y ) { return atan2f( x, y ); }
-double atan2( double x, double y ) { return atan2( x, y ); }
 long double atan2( long double x, long double y ) { return atan2l( x, y ); }
 
