https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129187
Bug ID: 129187
Summary: [modules] Spurious "conflicting declaration of
template" with alias to auto variable template from a
module GMF
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: yansendao at 126 dot com
Target Milestone: ---
A header textually included both in a module's global module fragment and in
the importing TU is parsed twice. GCC merges the declarations normally, but
an alias template whose RHS refers to an auto-deduced variable template is
reported as conflicting even though both declarations are identical.
Exposed by libstdc++ commit db7ef921c00 (P1317R2), which added to
<type_traits>:
template<template<typename...> class _Trait, typename _Tp, typename _Tuple>
constexpr auto __unpack_tuple_like_impl = false_type{};
template<template<typename...> class _Trait, typename _Tp, typename _Tuple>
using __unpack_tuple_like
= remove_cv_t<decltype(__unpack_tuple_like_impl<_Trait, _Tp, _Tuple>)>;
Reproducer:
// hdr.h
namespace std { inline namespace __cxx11 {
struct false_type { static constexpr bool value = false; };
template<typename...> struct trait { using type = int; };
template<typename T> struct remove_cv { using type = T; };
template<typename T> using remove_cv_t = typename remove_cv<T>::type;
template<template<typename...> class T, typename A, typename B>
constexpr auto impl_v = false_type{};
template<template<typename...> class T, typename A, typename B>
using alias_t = remove_cv_t<decltype(impl_v<T, A, B>)>;
}}
// mod.C
module; #include "hdr.h"
export module m;
export using X = std::alias_t<std::trait, int, int>;
// main.C
import m; #include "hdr.h"
int main () { X x; }
$ g++ -std=c++20 -fmodules-ts -c mod.C
$ g++ -std=c++20 -fmodules -fno-module-lazy -c main.C
main.C:2:7: error: conflicting declaration of template
'...using std::__cxx11::alias_t = ...remove_cv_t<decltype (impl_v<...>)>'
mod.C:2:7: note: previous declaration (same text)
Without -fno-module-lazy the message is "conflicting imported declaration".
Changing impl_v to an explicit type (constexpr false_type impl_v = ...) or
making alias_t not depend on it makes the error disappear, so the auto-deduced
variable template is the trigger. A plain auto variable does not reproduce.
Using the headers from db7ef921c00^ with the same compiler also passes.
This breaks trunk tests on x86_64 and aarch64 (519344b0ee1):
FAIL: g++.dg/modules/hello-1_b.C -std=c++20 / c++29 (test for excess errors)
UNRESOLVED: g++.dg/modules/hello-1 -std=c++20 / c++29 execute, link
FAIL: g++.dg/modules/compile-std1.C -std=c++29 (test for excess errors)
hello-1_b.C imports hello (<iostream> in its GMF) then includes <string_view>;
compile-std1.C imports std then includes <bits/stdc++.h>. Both re-include
<type_traits> textually.