[clang] [Clang] Correctly initialize placeholder fields from their initializers (PR #114196)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 5 07:02:00 PST 2024


================
@@ -5560,6 +5560,25 @@ ExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation CallLoc,
                                    Init, InitializationContext->Context);
 }
 
+static FieldDecl *FindFieldDeclInstantiationPattern(const ASTContext &Ctx,
+                                                    FieldDecl *Field) {
+  if (FieldDecl *Pattern = Ctx.getInstantiatedFromUnnamedFieldDecl(Field))
+    return Pattern;
+  auto *ParentRD = cast<CXXRecordDecl>(Field->getParent());
+  CXXRecordDecl *ClassPattern = ParentRD->getTemplateInstantiationPattern();
+  DeclContext::lookup_result Lookup =
+      ClassPattern->lookup(Field->getDeclName());
+  auto Rng = llvm::make_filter_range(Lookup, [] (auto && L) {
+      return isa<FieldDecl>(*L);
+  });
+  // FIXME: this breaks clang/test/Modules/pr28812.cpp
+  // assert(std::distance(Rng.begin(), Rng.end()) <= 1
+  //       && "Duplicated instantiation pattern for field decl");
+  if(Rng.empty())
----------------
erichkeane wrote:

woops, I meant 'below'.  Basically, just move 5577 to above 5574.  Sorry about that :/

Basically, doing the `std::distance` check (when we re-enable it) before checking for `empty` seems silly.

https://github.com/llvm/llvm-project/pull/114196


More information about the cfe-commits mailing list