[clang] [Clang] Eagerly instantiate used constexpr function upon definition. (PR #73463)

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 28 11:55:41 PST 2023


================
@@ -6481,6 +6481,33 @@ void Sema::PerformPendingInstantiations(bool LocalOnly) {
     PendingInstantiations.swap(delayedPCHInstantiations);
 }
 
+// Instantiate all referenced specializations of the given function template
+// definition. This make sure that function template that are defined after the
+// point of instantiation of their used can be evaluated after they are defined.
+// see CWG2497.
+void Sema::InstantiateFunctionTemplateSpecializations(
+    SourceLocation PointOfInstantiation, FunctionDecl *Tpl) {
+
+  auto InstantiateAll = [&](const auto &Range) {
+    for (NamedDecl *Fun : Range) {
+      InstantiateFunctionDefinition(PointOfInstantiation,
+                                    cast<FunctionDecl>(Fun));
+    }
+  };
+
+  auto It =
+      PendingInstantiationsOfConstexprEntities.find(Tpl->getCanonicalDecl());
+  if (It != PendingInstantiationsOfConstexprEntities.end()) {
+    InstantiateAll(It->second);
----------------
zygoloid wrote:

Is this iterator guaranteed to remain valid throughout this call? We might add new keys to the map. Maybe we should move the vector out of the map first.

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


More information about the cfe-commits mailing list