For the pair(T1, T2) explicit deduction type to decay its arguments as
intended, we need the pair(const T1&, const T2&) constructor to not be
used for CTAD. Otherwise we try to instantiate pair<T1, T2> without
decaying, which is ill-formed for function lvalues.
Use std::type_identity_t<T1> to make the constructor unusable for an
implicit deduction guide.
libstdc++-v3/ChangeLog:
PR libstdc++/110853
* include/bits/stl_pair.h [C++20] (pair(const T1&, const T2&)):
Use std::type_identity_t<T1> for first parameter.
* testsuite/20_util/pair/cons/110853.cc: New test.
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Tomasz KamiĆski <tkaminsk@redhat.com>
(cherry picked from commit
0bb0d1d2880d562298eeec8eee4ab4e8ba943260)
/// Constructor accepting lvalues of `first_type` and `second_type`
constexpr explicit(!_S_convertible<const _T1&, const _T2&>())
- pair(const _T1& __x, const _T2& __y)
+ pair(const type_identity_t<_T1>& __x, const _T2& __y)
noexcept(_S_nothrow_constructible<const _T1&, const _T2&>())
requires (_S_constructible<const _T1&, const _T2&>())
: first(__x), second(__y)
--- /dev/null
+// { dg-do compile { target c++17 } }
+// PR libstdc++/110853
+// Bad interaction between deduction guide with decay and constraints
+// (CTAD, std::pair and function lvalue)
+
+#include <utility>
+
+void func() {}
+std::pair p(1, func);
+std::pair<int, void (*)()>& r = p;