summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Sema/SemaDeclCXX.cpp11
-rw-r--r--clang/test/Modules/Inputs/PR28812/Textual.h11
-rw-r--r--clang/test/Modules/Inputs/PR28812/a.h1
-rw-r--r--clang/test/Modules/Inputs/PR28812/b.h1
-rw-r--r--clang/test/Modules/Inputs/PR28812/module.modulemap6
-rw-r--r--clang/test/Modules/pr28812.cpp22
6 files changed, 50 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index f49525c6e45..518a780a4ea 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -12321,13 +12321,20 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field) {
// Lookup can return at most two results: the pattern for the field, or the
// injected class name of the parent record. No other member can have the
// same name as the field.
- assert(!Lookup.empty() && Lookup.size() <= 2 &&
+ // In modules mode, lookup can return multiple results (coming from
+ // different modules).
+ assert((getLangOpts().Modules || (!Lookup.empty() && Lookup.size() <= 2)) &&
"more than two lookup results for field name");
FieldDecl *Pattern = dyn_cast<FieldDecl>(Lookup[0]);
if (!Pattern) {
assert(isa<CXXRecordDecl>(Lookup[0]) &&
"cannot have other non-field member with same name");
- Pattern = cast<FieldDecl>(Lookup[1]);
+ for (auto L : Lookup)
+ if (isa<FieldDecl>(L)) {
+ Pattern = cast<FieldDecl>(L);
+ break;
+ }
+ assert(Pattern && "We must have set the Pattern!");
}
if (InstantiateInClassInitializer(Loc, Field, Pattern,
diff --git a/clang/test/Modules/Inputs/PR28812/Textual.h b/clang/test/Modules/Inputs/PR28812/Textual.h
new file mode 100644
index 00000000000..769962e0879
--- /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 00000000000..0d9da60c91c
--- /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 00000000000..0d9da60c91c
--- /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 00000000000..d2d2b4a0c34
--- /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 00000000000..78267d2a4b4
--- /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
+
OpenPOWER on IntegriCloud