From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id D72BE3858C55; Tue, 20 Sep 2022 20:14:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D72BE3858C55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663704889; bh=5X5FRCUfAWNzUWZf53A9hb+UOTE4bo3pm95klyN6vTM=; h=From:To:Subject:Date:From; b=IIvReFGgzyVDgueeXwpmTDf4Rc5iEYURTxQ3fyVSIaJinDebKbKGm2L0EtcMYYuOn o0bB6yBl7h28FocvSkJpXDEq0eCK/rQKI2t2MeklZ5X+t7KNxT/zqEzRxFtaYM2B8+ 8Fmc0vNc0v4tFTKvoqmZJYKoe85qYBepgkPtBk3U= 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 r13-2744] c++: modules and non-dependent auto deduction X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: be60aa5b608b5f09fadfeff852a46589ac311a42 X-Git-Newrev: 4fac53d652218946b82af4431a801ab1551f0e79 Message-Id: <20220920201449.D72BE3858C55@sourceware.org> Date: Tue, 20 Sep 2022 20:14:49 +0000 (GMT) List-Id: https://gcc.gnu.org/g:4fac53d652218946b82af4431a801ab1551f0e79 commit r13-2744-g4fac53d652218946b82af4431a801ab1551f0e79 Author: Patrick Palka Date: Tue Sep 20 16:08:14 2022 -0400 c++: modules and non-dependent auto deduction The modules streaming code seems to rely on the invariant that a TEMPLATE_DECL and its DECL_TEMPLATE_RESULT have the same TREE_TYPE. But for a non-dependent VAR_DECL with deduced type, the two TREE_TYPEs end up diverging: cp_finish_decl deduces the type of the initializer ahead of time and updates the TREE_TYPE of the VAR_DECL, but neglects to update the corresponding TEMPLATE_DECL as well, which leads to a "conflicting global module declaration" error for each of the __phase_alignment decls in the below testcase (and for the xtreme-header tests if we try including ). This patch makes cp_finish_decl update the TREE_TYPE of the corresponding TEMPLATE_DECL so that the invariant is maintained. gcc/cp/ChangeLog: * decl.cc (cp_finish_decl): After updating the deduced type of a VAR_DECL, also update the corresponding TEMPLATE_DECL if there is one. gcc/testsuite/ChangeLog: * g++.dg/modules/auto-3.h: New test. * g++.dg/modules/auto-3_a.H: New test. * g++.dg/modules/auto-3_b.C: New test. Diff: --- gcc/cp/decl.cc | 6 ++++++ gcc/testsuite/g++.dg/modules/auto-3.h | 10 ++++++++++ gcc/testsuite/g++.dg/modules/auto-3_a.H | 4 ++++ gcc/testsuite/g++.dg/modules/auto-3_b.C | 4 ++++ 4 files changed, 24 insertions(+) diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 070f673c3a2..80467c19254 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -8180,6 +8180,12 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, return; } cp_apply_type_quals_to_decl (cp_type_quals (type), decl); + + /* Update the type of the corresponding TEMPLATE_DECL to match. */ + if (DECL_LANG_SPECIFIC (decl) + && DECL_TEMPLATE_INFO (decl) + && DECL_TEMPLATE_RESULT (DECL_TI_TEMPLATE (decl)) == decl) + TREE_TYPE (DECL_TI_TEMPLATE (decl)) = type; } if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node) diff --git a/gcc/testsuite/g++.dg/modules/auto-3.h b/gcc/testsuite/g++.dg/modules/auto-3.h new file mode 100644 index 00000000000..f129433cbcb --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/auto-3.h @@ -0,0 +1,10 @@ +template +struct __tree_barrier { + static const auto __phase_alignment_1 = 0; + + template + static const auto __phase_alignment_2 = 0; +}; + +template +inline auto __phase_alignment_3 = 0; diff --git a/gcc/testsuite/g++.dg/modules/auto-3_a.H b/gcc/testsuite/g++.dg/modules/auto-3_a.H new file mode 100644 index 00000000000..25a7a73e73e --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/auto-3_a.H @@ -0,0 +1,4 @@ +// { dg-additional-options "-fmodule-header" } +// { dg-module-cmi {} } + +#include "auto-3.h" diff --git a/gcc/testsuite/g++.dg/modules/auto-3_b.C b/gcc/testsuite/g++.dg/modules/auto-3_b.C new file mode 100644 index 00000000000..03b6d46f476 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/auto-3_b.C @@ -0,0 +1,4 @@ +// { dg-additional-options "-fmodules-ts -fno-module-lazy" } + +#include "auto-3.h" +import "auto-3_a.H";