Author: Richard Smith
Date: 2020-11-18T14:04:02-08:00
New Revision: 5f2c5541f78750c21004e0172f13db4632966fd3

URL: 
https://github.com/llvm/llvm-project/commit/5f2c5541f78750c21004e0172f13db4632966fd3
DIFF: 
https://github.com/llvm/llvm-project/commit/5f2c5541f78750c21004e0172f13db4632966fd3.diff

LOG: Fix assert on valid due to incorrect assumption that a field name must
be unique in its scope.

Added: 
    clang/test/SemaTemplate/default-member-init.cpp

Modified: 
    clang/lib/Sema/SemaDeclCXX.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index d31d2e32547a..9d2090dfd8eb 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -15082,24 +15082,14 @@ ExprResult 
Sema::BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field) {
     DeclContext::lookup_result Lookup =
         ClassPattern->lookup(Field->getDeclName());
 
-    // 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.
-    // In modules mode, lookup can return multiple results (coming from
-    // 
diff erent 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");
-      for (auto L : Lookup)
-        if (isa<FieldDecl>(L)) {
-          Pattern = cast<FieldDecl>(L);
-          break;
-        }
-      assert(Pattern && "We must have set the Pattern!");
+    FieldDecl *Pattern = nullptr;
+    for (auto L : Lookup) {
+      if (isa<FieldDecl>(L)) {
+        Pattern = cast<FieldDecl>(L);
+        break;
+      }
     }
+    assert(Pattern && "We must have set the Pattern!");
 
     if (!Pattern->hasInClassInitializer() ||
         InstantiateInClassInitializer(Loc, Field, Pattern,

diff  --git a/clang/test/SemaTemplate/default-member-init.cpp 
b/clang/test/SemaTemplate/default-member-init.cpp
new file mode 100644
index 000000000000..5615d11e33d6
--- /dev/null
+++ b/clang/test/SemaTemplate/default-member-init.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// expected-no-diagnostics
+
+struct Q { enum F { f }; };
+
+template<typename T> struct A : Q {
+  enum E { e } E = e;
+
+  using Q::F;
+  Q::F F = f;
+};
+A<int> a = {};


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to