[modules] PR28812: Modules can return duplicate field decls.

If two modules contain duplicate class definitions the lookup result can contain
more than 2 elements. Sift the lookup results until we find a field decl.

It is not necessary to do ODR checks in place as they done elsewhere.

This should fix issues when compiling with libstdc++ 5.2 and 6.2.

Patch developed in collaboration with Richard Smith!

llvm-svn: 285184
diff --git a/clang/test/Modules/Inputs/PR28812/Textual.h b/clang/test/Modules/Inputs/PR28812/Textual.h
new file mode 100644
index 0000000..769962e
--- /dev/null
+++ b/clang/test/Modules/Inputs/PR28812/Textual.h
@@ -0,0 +1,11 @@
+#ifndef T_H
+#define T_H
+
+template <typename ValueType> struct VarStreamArray;
+
+template <typename ValueType> struct VarStreamArrayIterator {
+  VarStreamArrayIterator(VarStreamArray<ValueType>) {}
+  bool HasError{};
+};
+
+#endif // T_H
diff --git a/clang/test/Modules/Inputs/PR28812/a.h b/clang/test/Modules/Inputs/PR28812/a.h
new file mode 100644
index 0000000..0d9da60
--- /dev/null
+++ b/clang/test/Modules/Inputs/PR28812/a.h
@@ -0,0 +1 @@
+#include "Textual.h"
diff --git a/clang/test/Modules/Inputs/PR28812/b.h b/clang/test/Modules/Inputs/PR28812/b.h
new file mode 100644
index 0000000..0d9da60
--- /dev/null
+++ b/clang/test/Modules/Inputs/PR28812/b.h
@@ -0,0 +1 @@
+#include "Textual.h"
diff --git a/clang/test/Modules/Inputs/PR28812/module.modulemap b/clang/test/Modules/Inputs/PR28812/module.modulemap
new file mode 100644
index 0000000..d2d2b4a
--- /dev/null
+++ b/clang/test/Modules/Inputs/PR28812/module.modulemap
@@ -0,0 +1,6 @@
+module "A" {
+  header "a.h"
+}
+module "B" { 
+  header "b.h"
+}
diff --git a/clang/test/Modules/pr28812.cpp b/clang/test/Modules/pr28812.cpp
new file mode 100644
index 0000000..78267d2
--- /dev/null
+++ b/clang/test/Modules/pr28812.cpp
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -std=c++11 -nostdsysteminc -I%S/Inputs/PR28812 -verify %s
+// RUN: %clang_cc1 -std=c++11 -nostdsysteminc -fmodules -fimplicit-module-maps \
+// RUN:            -fmodules-cache-path=%t -I%S/Inputs/PR28812 -verify %s
+
+template <typename> struct VarStreamArrayIterator;
+template <typename ValueType>
+struct VarStreamArray {
+  typedef VarStreamArrayIterator<ValueType> Iterator;
+  Iterator begin() { return Iterator(*this); }
+};
+
+#include "Textual.h"
+
+#include "a.h"
+#include "b.h"
+
+VarStreamArray<int> a;
+auto b = a.begin();
+
+// expected-no-diagnostics
+