From a1379613b3471995fe00293ad42ca22d64545322 Mon Sep 17 00:00:00 2001 From: cpplearner Date: Sat, 17 Oct 2026 20:03:26 +0800 Subject: [PATCH] Fix SFINAE for function template with deduced return type and pending definition [GH #453] --- src/exprutil.c | 8 +++++--- src/pending_changes/gh-453.txt | 7 +++++++ .../modules/gh-453-template-return-auto/A.ifc | Bin 0 -> 1855 bytes .../modules/gh-453-template-return-auto/A.ixx | 7 +++++++ .../gh-453-template-return-auto/test.mft.cpp | 13 +++++++++++++ 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/pending_changes/gh-453.txt create mode 100644 tests/tests/regressions/modules/gh-453-template-return-auto/A.ifc create mode 100644 tests/tests/regressions/modules/gh-453-template-return-auto/A.ixx create mode 100644 tests/tests/regressions/modules/gh-453-template-return-auto/test.mft.cpp diff --git a/src/exprutil.c b/src/exprutil.c index c9bb061c90..7a46ecca17 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 */ @@ -18149,11 +18150,12 @@ reference entry, or is NULL if none is needed. if (tip != NULL) { a_symbol_ptr tsym; tsym = prototype_template_if_template_symbol(tip->template_sym); - if (tsym->defined) { + if (tsym->defined || + 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) { + } else if (routine->friend_defined_in_instantiation) { could_be_instantiated = TRUE; } /* if */ if (!could_be_instantiated) { diff --git a/src/pending_changes/gh-453.txt b/src/pending_changes/gh-453.txt new file mode 100644 index 0000000000..4c26018108 --- /dev/null +++ b/src/pending_changes/gh-453.txt @@ -0,0 +1,7 @@ +[GH #453] +SFINAE for function template with pending definition and deduced return type + +With modules, it is possible that a function template definition exists in a +module but the definition is not yet loaded. Previously, substitution failed +if such a function template is called in a SFINAE context and the function +template has a deduced return type. This is now fixed. diff --git a/tests/tests/regressions/modules/gh-453-template-return-auto/A.ifc b/tests/tests/regressions/modules/gh-453-template-return-auto/A.ifc new file mode 100644 index 0000000000000000000000000000000000000000..a4e1db37bf2f3cc27508524b2a653e046db99cbd GIT binary patch literal 1855 zcmah~&ubJ{9DmvT(4;m-X{zsrRYJhf)r1B$w@5qP!%e8@KC(@`MjAIXCdHYKl{F)@9*!MH@me{ zlRN(U@pbm<@!8dT$Ci7qO>BPPAJ{Q;NbQSWPK~_0`|jcmF)Aushr7i}w-5&_Li7tE zAc`*FS+5Y=uyYOMo7SI$3|H|rFjDBbF~*>z78}c?B*!R3f0S9vPnnDQvfb!57dF=C zqM!L@?kSm&V4$dw_Zf6ayL1bXOIim{v z%k{dddA+sSs-Nt-f7r|ZqGV_OUgYb+PUr=DnID7)`4<4sh1tlz1i1R4HMO+@@nzok z89Vzg`*$IJ3la?iti#?}m%8)DLHuW&Z~ zaA!~4**ACkaOX2M&xt$p(#PB@;}4ad#pGe^o%eqnep<=SEcai1VgEhyH2US+m75R6 zzk7c^()awEQ-7A9p}89yaWGqeVPF>zX-tgS{^FvTIM5ic*BjDnx^Zl|Q9JennKYD4 zRa$(fPUy`=i;ZT>`tJMvmXhr_aFnzXsj?)roJ>WHJXz{Sv9vvzx*`|bvOOmgF&~PW z@T42qv6DD$si4zzJ_}vtM`6xPW|1bYeLhM&Eu=D3GIXU-OGu6g4;ez`1i1p${AP%L zyqpIMPLQ#=d6{&C<%M(-^zX`66nN-EF2;!+_-F|k-IkLmI}33J3o;OK;xyZiohqak zb~{~gZIw8_vU7uV-bq3~Y^J);zz;i}LiFibW<+ak^t2-tM)B2><%hoVoxr~!6Dx?^ ztkY>84Ow#$XHS+o!due86c$=mRvKlAD=j*A_~_`ClePp~vdeC> +auto fn(T&) +{ + return 42; +} diff --git a/tests/tests/regressions/modules/gh-453-template-return-auto/test.mft.cpp b/tests/tests/regressions/modules/gh-453-template-return-auto/test.mft.cpp new file mode 100644 index 0000000000..201eefd8ce --- /dev/null +++ b/tests/tests/regressions/modules/gh-453-template-return-auto/test.mft.cpp @@ -0,0 +1,13 @@ +//type:fp +//options_all:--ms_c++20 -tused --modules --microsoft_version 1952 --ms_mod_file_map A.ifc --target win64 + +import A; + +template +concept C = requires(T& t) { + ::fn(t); +}; + +static_assert(C); + +int main() {}