https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124978
Bug ID: 124978
Summary: Wrong type with decltype of auto template parameter
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: rs2740 at gmail dot com
Target Milestone: ---
template<auto X, class = decltype(X)>
struct cw;
struct base {
template <class L, class R>
friend constexpr auto operator ->*(L, R) noexcept
-> cw<(L::value ->* R::value)> {
return {};
}
template <class L>
friend constexpr auto operator &(L) noexcept
-> cw<(&L::value)> {
return {};
}
};
template<auto X, class>
struct cw : base {
static constexpr const auto& value = X;
};
struct Divide { int value; };
auto cvalue = cw<&Divide::value>{};
auto co = cw<Divide{42}>{};
template<class> class TD;
TD<decltype((&co)->*cvalue)> _;
<source>:29:30: error: aggregate 'TD<cw<42, const int*> > _' has incomplete
type and cannot be defined
29 | TD<decltype((&co)->*cvalue)> _;
| ^
It's unclear where the pointer came from - this is expected to be cw<42, int>.
Using decltype(auto(X)) as the default template argument seems to work, but
remove_cvref_t<decltype(X)> doesn't.
Probably related to PR115314, but the symptom goes beyond the extra "const".