diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 102a6ae..7465131 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -3941,7 +3941,8 @@ void
 Sema::RegisterLocallyScopedExternCDecl(NamedDecl *ND,
                                        const LookupResult &Previous,
                                        Scope *S) {
-  assert(ND->getLexicalDeclContext()->isFunctionOrMethod() &&
+  assert((ND->getLexicalDeclContext()->isFunctionOrMethod() ||
+          ND->getLexicalDeclContext()->getDeclKind() == Decl::LinkageSpec) &&
          "Decl is not a locally-scoped decl!");
   // Note that we have a locally-scoped external with this name.
   LocallyScopedExternalDecls[ND->getDeclName()] = ND;
@@ -4509,8 +4510,9 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
 
   // If this is a locally-scoped extern C variable, update the map of
   // such variables.
-  if (CurContext->isFunctionOrMethod() && NewVD->isExternC() &&
-      !NewVD->isInvalidDecl())
+  if ((CurContext->isFunctionOrMethod() ||
+       CurContext->getDeclKind() == Decl::LinkageSpec) &&
+      NewVD->isExternC() && !NewVD->isInvalidDecl())
     RegisterLocallyScopedExternCDecl(NewVD, Previous, S);
 
   // If there's a #pragma GCC visibility in scope, and this isn't a class
@@ -5993,8 +5995,9 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
 
   // If this is a locally-scoped extern C function, update the
   // map of such names.
-  if (CurContext->isFunctionOrMethod() && NewFD->isExternC()
-      && !NewFD->isInvalidDecl())
+  if ((CurContext->isFunctionOrMethod() ||
+       CurContext->getDeclKind() == Decl::LinkageSpec) &&
+      NewFD->isExternC() && !NewFD->isInvalidDecl())
     RegisterLocallyScopedExternCDecl(NewFD, Previous, S);
 
   // Set this FunctionDecl's range up to the right paren.
diff --git a/test/SemaCXX/PR10447.cpp b/test/SemaCXX/PR10447.cpp
index 5ba74aa..54c0a8e 100644
--- a/test/SemaCXX/PR10447.cpp
+++ b/test/SemaCXX/PR10447.cpp
@@ -17,7 +17,7 @@ namespace test1 {
 // PR10447
 namespace test2 {
   extern "C" {
-    void f(struct Bar*) { }
+    void g(struct Bar*) { }
     test2::Bar *ptr;
   }
 }
diff --git a/test/SemaCXX/linkage-spec.cpp b/test/SemaCXX/linkage-spec.cpp
index cb7e32c..8abad1e 100644
--- a/test/SemaCXX/linkage-spec.cpp
+++ b/test/SemaCXX/linkage-spec.cpp
@@ -102,3 +102,27 @@ namespace PR9162 {
     return sizeof(ArtsSink);
   }
 }
+
+namespace PR12299 {
+  namespace A {
+    extern "C" void a();
+    extern "C" int b;
+    extern "C" void c(); // expected-note {{previous declaration}}
+    extern "C" int e; // expected-note {{previous definition}}
+  }
+
+  namespace B {
+    extern "C" void a();
+    extern "C" int b;
+    extern "C" void c(int); // expected-error {{conflicting}}
+    extern "C" char e; // expected-error {{redefinition}}
+  }
+
+  using namespace A;
+  using namespace B;
+
+  void g() {
+    b = 1;
+    a();
+  }
+}
