https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121761
Bug ID: 121761
Summary: [13/14/15/16 Regression] std::pair deduction guide
doesn't decay functions in C++20 mode
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
#include <utility>
void func() {}
std::pair p(func, 1);
std::pair<void (*)(), int>& r = p;
This fails to compile with -std=gnu++20
In file included from /home/jwakely/gcc/16/include/c++/16.0.0/utility:71,
from pair.cc:1:
/home/jwakely/gcc/16/include/c++/16.0.0/bits/stl_pair.h: In instantiation of
'struct std::pair<void(), int>':
required by substitution of 'template<class _T1, class _T2> pair(const _T1&,
const _T2&) -> std::pair<_T1, _T2> requires (std::pair<_T1,
_T2>::_S_constructible<const _T1&, const _T2&>)() [with _T1 = void(); _T2 =
int]'
/home/jwakely/gcc/16/include/c++/16.0.0/bits/stl_pair.h:450:57:
450 | requires (_S_constructible<const _T1&, const _T2&>())
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
required from here
pair.cc:3:20:
3 | std::pair p(func, 1);
| ^
/home/jwakely/gcc/16/include/c++/16.0.0/bits/stl_pair.h:308:11: error: data
member 'std::pair<void(), int>::first' invalidly declared function type
308 | _T1 first; ///< The first member
| ^~~~~
There's a deduction guide that should decay the function to a pointer:
#if __cpp_deduction_guides >= 201606
template<typename _T1, typename _T2> pair(_T1, _T2) -> pair<_T1, _T2>;
#endif
But the error shows that we're trying to instantiate pair<void(&)(), int>.
This is caused by the concepts-based implementation, which was added in GCC 12.
Before that the same code was used in C++20 mode as for C++17 mode, and the
decaying works correctly.