summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDeclCXX.cpp
diff options
context:
space:
mode:
authorVassil Vassilev <v.g.vassilev@gmail.com>2016-10-26 10:24:29 +0000
committerVassil Vassilev <v.g.vassilev@gmail.com>2016-10-26 10:24:29 +0000
commite53a4b7402ed311d06e25adfce44b6d12b7c89b1 (patch)
treeea984b2bb66c5451fdfb77110aa7335799f6c79d /clang/lib/Sema/SemaDeclCXX.cpp
parentdf5042ab613a71d0fee0e1ac8a36a22b1f8bc241 (diff)
downloadbcm5719-llvm-e53a4b7402ed311d06e25adfce44b6d12b7c89b1.tar.gz
bcm5719-llvm-e53a4b7402ed311d06e25adfce44b6d12b7c89b1.zip
[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
Diffstat (limited to 'clang/lib/Sema/SemaDeclCXX.cpp')
-rw-r--r--clang/lib/Sema/SemaDeclCXX.cpp11
1 files changed, 9 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,
OpenPOWER on IntegriCloud