Slightly improve cross-module merging for function templates.

llvm-svn: 184689
diff --git a/clang/test/Modules/Inputs/cxx-templates-a.h b/clang/test/Modules/Inputs/cxx-templates-a.h
new file mode 100644
index 0000000..52bc3a2
--- /dev/null
+++ b/clang/test/Modules/Inputs/cxx-templates-a.h
@@ -0,0 +1,6 @@
+template<typename T> T f() { return T(); }
+template<typename T> T f(T);
+namespace N {
+  template<typename T> T f() { return T(); }
+  template<typename T> T f(T);
+}
diff --git a/clang/test/Modules/Inputs/cxx-templates-b.h b/clang/test/Modules/Inputs/cxx-templates-b.h
new file mode 100644
index 0000000..3cc940c
--- /dev/null
+++ b/clang/test/Modules/Inputs/cxx-templates-b.h
@@ -0,0 +1,6 @@
+template<typename T> T f();
+template<typename T> T f(T t) { return t; }
+namespace N {
+  template<typename T> T f();
+  template<typename T> T f(T t) { return t; }
+}
diff --git a/clang/test/Modules/Inputs/module.map b/clang/test/Modules/Inputs/module.map
index 65c75fd..d2ed758 100644
--- a/clang/test/Modules/Inputs/module.map
+++ b/clang/test/Modules/Inputs/module.map
@@ -188,6 +188,14 @@
   header "cxx-linkage-cache.h"
 }
 
+module cxx_templates_a {
+  header "cxx-templates-a.h"
+}
+
+module cxx_templates_b {
+  header "cxx-templates-b.h"
+}
+
 module config {
   header "config.h"
   config_macros [exhaustive] WANT_FOO, WANT_BAR
diff --git a/clang/test/Modules/cxx-templates.cpp b/clang/test/Modules/cxx-templates.cpp
new file mode 100644
index 0000000..bc96772
--- /dev/null
+++ b/clang/test/Modules/cxx-templates.cpp
@@ -0,0 +1,41 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump -ast-dump-lookups | FileCheck %s --check-prefix=CHECK-GLOBAL
+// RUN: %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump -ast-dump-lookups -ast-dump-filter N | FileCheck %s --check-prefix=CHECK-NAMESPACE-N
+// RUN: %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++11
+
+@import cxx_templates_a;
+@import cxx_templates_b;
+
+void g() {
+  f(0);
+  f<double>(1.0);
+  f<int>();
+  f(); // expected-error {{no matching function}}
+  // expected-note@Inputs/cxx-templates-b.h:1 {{couldn't infer template argument}}
+  // expected-note@Inputs/cxx-templates-b.h:2 {{requires single argument}}
+
+  N::f(0);
+  N::f<double>(1.0);
+  N::f<int>();
+  N::f(); // expected-error {{no matching function}}
+  // expected-note@Inputs/cxx-templates-a.h:4 {{couldn't infer template argument}}
+  // expected-note@Inputs/cxx-templates-a.h:5 {{requires 1 argument, but 0 were provided}}
+}
+
+// FIXME: There should only be two 'f's here.
+// CHECK-GLOBAL:      DeclarationName 'f'
+// CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
+// CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
+// CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
+// CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
+// CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
+// CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
+// CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
+// CHECK-GLOBAL-NEXT: `-FunctionTemplate {{.*}} 'f'
+
+// FIXME: There should only be two 'f's here.
+// CHECK-NAMESPACE-N:      DeclarationName 'f'
+// CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f'
+// CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f'
+// CHECK-NAMESPACE-N-NEXT: |-FunctionTemplate {{.*}} 'f'
+// CHECK-NAMESPACE-N-NEXT: `-FunctionTemplate {{.*}} 'f'