================
@@ -3430,15 +3430,17 @@ bool Sema::SubstDefaultArgument(
     ContextRAII SavedContext(*this, FD);
     std::unique_ptr<LocalInstantiationScope> LIS;
 
-    if (ForCallExpr) {
+    FunctionDecl *PatternFD =
+        ForCallExpr
+            ? FD->getTemplateInstantiationPattern(/*ForDefinition*/ false)
+            : nullptr;
+    if (PatternFD) {
       // When instantiating a default argument due to use in a call expression,
       // an instantiation scope that includes the parameters of the callee is
       // required to satisfy references from the default argument. For example:
       //   template<typename T> void f(T a, int = decltype(a)());
       //   void g() { f(0); }
       LIS = std::make_unique<LocalInstantiationScope>(*this);
-      FunctionDecl *PatternFD = FD->getTemplateInstantiationPattern(
-          /*ForDefinition*/ false);
----------------
a-tarasyuk wrote:

@mizvekov thanks for the detailed feedback.

> The tests added in this PR doesn't cover the non-trivial case where it does 
> refer to them.

I’d appreciate it if you could share an example of the non-trivial cases. This 
would help move forward with a new approach to resolve the issue and ensure 
that as many scenarios as possible are covered to prevent future crashes.



https://github.com/llvm/llvm-project/pull/113777
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to