aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2022-09-20 16:08:14 -0400
committerPatrick Palka <ppalka@redhat.com>2022-09-20 16:08:14 -0400
commit4fac53d652218946b82af4431a801ab1551f0e79 (patch)
treee1a50a80839153e7b0c8c62ee9112c698f5a64f4 /gcc/testsuite
parentbe60aa5b608b5f09fadfeff852a46589ac311a42 (diff)
downloadgcc-4fac53d652218946b82af4431a801ab1551f0e79.zip
gcc-4fac53d652218946b82af4431a801ab1551f0e79.tar.gz
gcc-4fac53d652218946b82af4431a801ab1551f0e79.tar.bz2
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 <barrier>). 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.
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/g++.dg/modules/auto-3.h10
-rw-r--r--gcc/testsuite/g++.dg/modules/auto-3_a.H4
-rw-r--r--gcc/testsuite/g++.dg/modules/auto-3_b.C4
3 files changed, 18 insertions, 0 deletions
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 0000000..f129433
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/auto-3.h
@@ -0,0 +1,10 @@
+template<class>
+struct __tree_barrier {
+ static const auto __phase_alignment_1 = 0;
+
+ template<class>
+ static const auto __phase_alignment_2 = 0;
+};
+
+template<class>
+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 0000000..25a7a73
--- /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 0000000..03b6d46
--- /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";