diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index 034790d..eb5fcde 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -1008,6 +1008,17 @@ static bool shouldTryToOverload(Sema &S, FunctionDecl *New, FunctionDecl *Old,
       isa<FunctionNoProtoType>(NewQType.getTypePtr()))
     return false;
 
+  // [dcl.link] p6
+  // An entity with C language linkage shall not be declared with
+  // the same name as an entity in global scope, unless both declarations denote
+  // the same entity
+  if (S.getLangOpts().CPlusPlus) {
+    if ((Old->isExternC() && New->getDeclContext()->isTranslationUnit()) ||
+        (Old->getDeclContext()->isTranslationUnit() &&
+         New->isInExternCContext()))
+      return false;
+  }
+
   const FunctionProtoType* OldType = cast<FunctionProtoType>(OldQType);
   const FunctionProtoType* NewType = cast<FunctionProtoType>(NewQType);
 
diff --git a/test/SemaCXX/linkage-spec.cpp b/test/SemaCXX/linkage-spec.cpp
index fc14081..01a03ae 100644
--- a/test/SemaCXX/linkage-spec.cpp
+++ b/test/SemaCXX/linkage-spec.cpp
@@ -41,15 +41,14 @@ namespace pr5430 {
 using namespace pr5430;
 extern "C" void pr5430::func(void) { }
 
-// PR5404
-int f2(char *)
+int f2(char *) // expected-note {{previous definition is here}}
 {
         return 0;
 }
 
 extern "C"
 {
-    int f2(int)
+    int f2(int) // expected-error {{declaration of 'f2' has a different language linkage}}
     {
         return f2((char *)0);
     }
diff --git a/test/SemaCXX/linkage2.cpp b/test/SemaCXX/linkage2.cpp
index a811575..f6b0eb8 100644
--- a/test/SemaCXX/linkage2.cpp
+++ b/test/SemaCXX/linkage2.cpp
@@ -201,3 +201,8 @@ namespace test18 {
   }
   void *h() { return f(); }
 }
+
+extern "C" void pr16247_foo(int); // expected-note {{previous declaration is here}}
+static void pr16247_foo(double); // expected-error {{static declaration of 'pr16247_foo' follows non-static declaration}}
+void pr16247_foo(int) { } // expected-note {{previous definition is here}}
+void pr16247_foo(double) {} // expected-error {{conflicting types for 'pr16247_foo'}}
