From ddfadcf2bbb55bb225c73b055af44eeb6da3a7b0 Mon Sep 17 00:00:00 2001 From: cpplearner Date: Sat, 17 Oct 2026 20:03:26 +0800 Subject: [PATCH 1/3] Fix SFINAE for function template with deduced return type and pending definition --- src/exprutil.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/exprutil.c b/src/exprutil.c index db22dd4b7b..3e2823d58f 100644 --- a/src/exprutil.c +++ b/src/exprutil.c @@ -33,6 +33,7 @@ exprutil.c -- Expression scanning utility routines. #include "lower_il.h" #endif /* DO_IL_LOWERING */ #include "statements.h" +#include "modules.h" #if USE_X86_FUNCTION_MULTIVERSIONING #include "sys_predef.h" #endif /* USE_X86_FUNCTION_MULTIVERSIONING */ @@ -18087,7 +18088,9 @@ reference entry, or is NULL if none is needed. } else if (routine->has_deducible_return_type && !routine->has_deduced_return_type && !routine->is_prototype_instantiation && - !routine->defined) { + !routine->defined && + !has_pending_template_definition_from_module( + routine->assoc_template)) { /* A function with a deducible return type that has not (yet) been deduced. If we are in a context where diagnostics are suppressed, treat the absence of a definition as a (suppressed) expression From 8c35348516de9326822aa5fa7323f1091f4cf38e Mon Sep 17 00:00:00 2001 From: cpplearner Date: Sun, 18 Oct 2026 10:02:23 +0800 Subject: [PATCH 2/3] Limit the check to template instances --- src/exprutil.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/exprutil.c b/src/exprutil.c index 3e2823d58f..5a4e94bd3a 100644 --- a/src/exprutil.c +++ b/src/exprutil.c @@ -18088,9 +18088,7 @@ reference entry, or is NULL if none is needed. } else if (routine->has_deducible_return_type && !routine->has_deduced_return_type && !routine->is_prototype_instantiation && - !routine->defined && - !has_pending_template_definition_from_module( - routine->assoc_template)) { + !routine->defined) { /* A function with a deducible return type that has not (yet) been deduced. If we are in a context where diagnostics are suppressed, treat the absence of a definition as a (suppressed) expression @@ -18103,6 +18101,9 @@ reference entry, or is NULL if none is needed. tsym = prototype_template_if_template_symbol(tip->template_sym); if (tsym->defined) { could_be_instantiated = TRUE; + } else if (has_pending_template_definition_from_module( + routine->assoc_template)) { + could_be_instantiated = TRUE; } /* if */ } else if (routine_sym->variant.routine.ptr ->friend_defined_in_instantiation) { From d2c8e301dbe0e463aab8350c9624fc0b895de9ef Mon Sep 17 00:00:00 2001 From: cpplearner Date: Sun, 18 Oct 2026 10:02:23 +0800 Subject: [PATCH 3/3] Drive by: simplify the `friend_defined_in_instantiation` check --- src/exprutil.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/exprutil.c b/src/exprutil.c index 5a4e94bd3a..dc543f200a 100644 --- a/src/exprutil.c +++ b/src/exprutil.c @@ -18105,8 +18105,7 @@ reference entry, or is NULL if none is needed. routine->assoc_template)) { could_be_instantiated = TRUE; } /* if */ - } else if (routine_sym->variant.routine.ptr - ->friend_defined_in_instantiation) { + } else if (routine->friend_defined_in_instantiation) { could_be_instantiated = TRUE; } /* if */ if (!could_be_instantiated) {