From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 305E4385840D; Tue, 23 Apr 2024 18:01:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 305E4385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713895309; bh=3cSBf7hz45o5xmX9f0c3KHCrdRRANXndCAPm10P76wg=; h=From:To:Subject:Date:From; b=potfwExWMXV6BplJ5GgKBsjtIeZQ7rjVIqScV4RAGnY/5weAkVnif9WXz4E69SHjv TfYP9nPL2LmNc0Zh3OCb7veGbsXmginLOaIsMlt8PbTnS1CBcQW3IXKR9oJjF/B08R etjBpYMr1AwD7UJohVGdaLEJohZe05ftH+WGuuqs= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-10096] c++/modules: deduced return type merging [PR114795] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: d2f05fed44951001de3cb02c9193c687e9376170 X-Git-Newrev: 4f9401d1a802325e5dfa2db841945e1a9c59a980 Message-Id: <20240423180149.305E4385840D@sourceware.org> Date: Tue, 23 Apr 2024 18:01:49 +0000 (GMT) List-Id: https://gcc.gnu.org/g:4f9401d1a802325e5dfa2db841945e1a9c59a980 commit r14-10096-g4f9401d1a802325e5dfa2db841945e1a9c59a980 Author: Patrick Palka Date: Tue Apr 23 14:01:22 2024 -0400 c++/modules: deduced return type merging [PR114795] When merging an imported function template specialization with an existing one, if the existing one has an undeduced return type and the imported one's is already deduced, we need to propagate the deduced type since once we install the imported definition we won't get a chance to deduce it by normal means. So this patch makes is_matching_decl propagate the deduced return type alongside our propagation of the exception specification. Another option would be to propagate it later when installing the imported definition from read_function_def, but it seems preferable to do it sooner rather than later. PR c++/114795 gcc/cp/ChangeLog: * module.cc (trees_in::is_matching_decl): Propagate deduced function return type. gcc/testsuite/ChangeLog: * g++.dg/modules/auto-4_a.H: New test. * g++.dg/modules/auto-4_b.C: New test. Reviewed-by: Jason Merrill Diff: --- gcc/cp/module.cc | 9 +++++++++ gcc/testsuite/g++.dg/modules/auto-4_a.H | 14 ++++++++++++++ gcc/testsuite/g++.dg/modules/auto-4_b.C | 15 +++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index d94d8ff4df9..c35e70b8cb8 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -11537,6 +11537,15 @@ trees_in::is_matching_decl (tree existing, tree decl, bool is_typedef) else if (!DEFERRED_NOEXCEPT_SPEC_P (d_spec) && !comp_except_specs (d_spec, e_spec, ce_type)) goto mismatch; + + /* Similarly if EXISTING has an undeduced return type, but DECL's + is already deduced. */ + if (undeduced_auto_decl (existing) && !undeduced_auto_decl (decl)) + { + dump (dumper::MERGE) + && dump ("Propagating deduced return type to %N", existing); + TREE_TYPE (existing) = change_return_type (TREE_TYPE (d_type), e_type); + } } else if (is_typedef) { diff --git a/gcc/testsuite/g++.dg/modules/auto-4_a.H b/gcc/testsuite/g++.dg/modules/auto-4_a.H new file mode 100644 index 00000000000..0f7cd262dfa --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/auto-4_a.H @@ -0,0 +1,14 @@ +// PR c++/114795 +// { dg-additional-options "-fmodule-header" } +// { dg-module-cmi {} } + +template +struct A { + auto f() { return T(); } +}; + +template +void g() { + A a; + a.f(); +} diff --git a/gcc/testsuite/g++.dg/modules/auto-4_b.C b/gcc/testsuite/g++.dg/modules/auto-4_b.C new file mode 100644 index 00000000000..378684ef6d0 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/auto-4_b.C @@ -0,0 +1,15 @@ +// PR c++/114795 +// { dg-additional-options "-fmodules-ts -fno-module-lazy" } + +template +struct A { + auto f() { return T(); } +}; + +A a; + +import "auto-4_a.H"; + +int main() { + g(); // { dg-bogus "before deduction of 'auto'" "" { target *-*-* } 0 } +}