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 0000000000..a4e1db37bf Binary files /dev/null and b/tests/tests/regressions/modules/gh-453-template-return-auto/A.ifc differ diff --git a/tests/tests/regressions/modules/gh-453-template-return-auto/A.ixx b/tests/tests/regressions/modules/gh-453-template-return-auto/A.ixx new file mode 100644 index 0000000000..c45ea008db --- /dev/null +++ b/tests/tests/regressions/modules/gh-453-template-return-auto/A.ixx @@ -0,0 +1,7 @@ +export module A; + +export template +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() {}