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.
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)
--- /dev/null
+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;
--- /dev/null
+// { dg-additional-options "-fmodule-header" }
+// { dg-module-cmi {} }
+
+#include "auto-3.h"
--- /dev/null
+// { dg-additional-options "-fmodules-ts -fno-module-lazy" }
+
+#include "auto-3.h"
+import "auto-3_a.H";