From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id B4C963858417 for ; Tue, 23 Apr 2024 16:41:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B4C963858417 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B4C963858417 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713890473; cv=none; b=G4Ci8gQj8FQrSbOLefzoepjcM1xIUHq/xDvTFa/Uzjv5eP7/MzjnT8crsIj2vMQ6I7cuM6oacP/CtMaWc2+qzPHI1HWTiSRCVjITMXKc6kr6ge5qLuev4QGyK4GJYj+nibsewVHDTZdrKMg2vV/Yutviamz2eHUZwFOEUEUrCJI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713890473; c=relaxed/simple; bh=Ta73yWJ6E4fkKPYjle0Y9qZabz0GeNlMGnzCAz+EoWU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kHmkbI16v7OYUd2yLxjRpRbNeBMzOji1mxcdRHn8cgFz3KZWedQaI73H3e3jm8/vxQ1Rv8dluhjHhk4CDQaDVu4yps1ZVrsTRDl1zwEgt2Vf/CCiHtfc4mZg0JYFrH+/h7xQda5UiaT58J1E7lgquBL/2u5tyCrlvelnRvyKLoU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713890467; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wDUYZprhmKnNg+UqAu/jVF3KAhlRqWga3u262PSeObA=; b=YhXPeN69WfAlOt48l4eJnJtMQMlpZQ1Uopy/V485zYe8C9l31X6zZwy9iE54t96nl6OCh1 akAQxk5up1yGGhOe21Q6or6hCPXozIKil1s5J6ITYlqQPGILFqx6jBJQ/272ZN5/yU3gaw j+lvySPK+ZEYW9MD+JWj771F/lDFQ4k= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-612-kGNgam1QOjaDc4QAqS6y4Q-1; Tue, 23 Apr 2024 12:41:06 -0400 X-MC-Unique: kGNgam1QOjaDc4QAqS6y4Q-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4393e712cd5so56265521cf.3 for ; Tue, 23 Apr 2024 09:41:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713890464; x=1714495264; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wDUYZprhmKnNg+UqAu/jVF3KAhlRqWga3u262PSeObA=; b=TaxEC5qQaFaTYt22M7wfQXrXS5oRHW6PC5cAZuivtxCuE/3ei4wum1WxY50pzU2EiX C6FNPPnMkjhFPBcPRAP2bw0oi30hcXjPERbLQObS31DJHi4VaT51aP+MAkDzyIYTtlyy +ctShK7qdkK0NK1NLFeyWLM9WgLIQQh/agtUI8++Nhtm7i7K80UqliKLvFOWfRpHkSDl xpEahbVvNIDv8bSGyXySdS1ap4ZO3lf2s4tUdLDz8oDhpnh/HmpuHGtMIjNCFyVE5yuZ vfN9dg3CKNHEPdqRo6hN2ExITMG4PKoK6WqgwzPqKdI0DheQ+OnjgPunLzJhgQWV7jcx L2hg== X-Gm-Message-State: AOJu0Yy9tuUVRba2540XOmFB0K7wjO61kq6J0xOfM9+ygrQ3H3RrnvGX wPlwnbVZFLtqeI5DwyuHlyrqeMHoBP/CYE+6aPqwEWshFcv9Io02iLNLFaeUhqc8bEjVwj2tcpz gGy9UKoecLoVCy+YPGy3p9InF7DrfLbb40KpoJmOwT16fbz2HhIH7VR3ueBn028LS/cXF5+MC0R sXyUCZ14DCwPn8J3c3TV29fN/uxGauwq1debAc X-Received: by 2002:a05:622a:208:b0:439:db10:84f5 with SMTP id b8-20020a05622a020800b00439db1084f5mr5073633qtx.28.1713890464120; Tue, 23 Apr 2024 09:41:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH7dC8GWKCTmdGgWmu3gWAlWlbVbzsD/zVw4B3rPUIVjyh+wqmhItaZGTe7i61rECqUYUUEEg== X-Received: by 2002:a05:622a:208:b0:439:db10:84f5 with SMTP id b8-20020a05622a020800b00439db1084f5mr5073606qtx.28.1713890463666; Tue, 23 Apr 2024 09:41:03 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id z1-20020ac81001000000b00434ee466ea6sm5291967qti.22.2024.04.23.09.41.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 09:41:03 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, nathanieloshead@gmail.com, Patrick Palka Subject: [PATCH] c++/modules: deduced return type merging [PR114795] Date: Tue, 23 Apr 2024 12:41:01 -0400 Message-ID: <20240423164101.3016046-1-ppalka@redhat.com> X-Mailer: git-send-email 2.45.0.rc0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- 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. This patch makes is_matching_decl propagate the deduced return type alongside the existing propagate of the existing specification. I suppose could instead propagate it later when installing the imported definition from read_definition, but it seems best to propagate 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. --- gcc/cp/module.cc | 5 +++++ gcc/testsuite/g++.dg/modules/auto-4_a.H | 14 ++++++++++++++ gcc/testsuite/g++.dg/modules/auto-4_b.C | 15 +++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/auto-4_a.H create mode 100644 gcc/testsuite/g++.dg/modules/auto-4_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index d94d8ff4df9..e10e19ac9f7 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -11537,6 +11537,11 @@ 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)) + 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..52b50533982 --- /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 0; } +}; + +template +inline 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 } +} -- 2.45.0.rc0