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

via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 5 06:54:31 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())
----------------
cor3ntin wrote:

I don't understand, can you clarify?

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


More information about the cfe-commits mailing list