Author: vvassilev Date: Wed Oct 26 05:24:29 2016 New Revision: 285184 URL: http://llvm.org/viewvc/llvm-project?rev=285184&view=rev Log: [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! Added: cfe/trunk/test/Modules/Inputs/PR28812/ cfe/trunk/test/Modules/Inputs/PR28812/Textual.h cfe/trunk/test/Modules/Inputs/PR28812/a.h cfe/trunk/test/Modules/Inputs/PR28812/b.h cfe/trunk/test/Modules/Inputs/PR28812/module.modulemap cfe/trunk/test/Modules/pr28812.cpp Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=285184&r1=285183&r2=285184&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Oct 26 05:24:29 2016 @@ -12321,13 +12321,20 @@ ExprResult Sema::BuildCXXDefaultInitExpr // 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, Added: cfe/trunk/test/Modules/Inputs/PR28812/Textual.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR28812/Textual.h?rev=285184&view=auto ============================================================================== --- cfe/trunk/test/Modules/Inputs/PR28812/Textual.h (added) +++ cfe/trunk/test/Modules/Inputs/PR28812/Textual.h Wed Oct 26 05:24:29 2016 @@ -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 Added: cfe/trunk/test/Modules/Inputs/PR28812/a.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR28812/a.h?rev=285184&view=auto ============================================================================== --- cfe/trunk/test/Modules/Inputs/PR28812/a.h (added) +++ cfe/trunk/test/Modules/Inputs/PR28812/a.h Wed Oct 26 05:24:29 2016 @@ -0,0 +1 @@ +#include "Textual.h" Added: cfe/trunk/test/Modules/Inputs/PR28812/b.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR28812/b.h?rev=285184&view=auto ============================================================================== --- cfe/trunk/test/Modules/Inputs/PR28812/b.h (added) +++ cfe/trunk/test/Modules/Inputs/PR28812/b.h Wed Oct 26 05:24:29 2016 @@ -0,0 +1 @@ +#include "Textual.h" Added: cfe/trunk/test/Modules/Inputs/PR28812/module.modulemap URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR28812/module.modulemap?rev=285184&view=auto ============================================================================== --- cfe/trunk/test/Modules/Inputs/PR28812/module.modulemap (added) +++ cfe/trunk/test/Modules/Inputs/PR28812/module.modulemap Wed Oct 26 05:24:29 2016 @@ -0,0 +1,6 @@ +module "A" { + header "a.h" +} +module "B" { + header "b.h" +} Added: cfe/trunk/test/Modules/pr28812.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/pr28812.cpp?rev=285184&view=auto ============================================================================== --- cfe/trunk/test/Modules/pr28812.cpp (added) +++ cfe/trunk/test/Modules/pr28812.cpp Wed Oct 26 05:24:29 2016 @@ -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 + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits