aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2025-09-02 22:30:46 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2025-09-03 10:49:12 +0100
commit0bb0d1d2880d562298eeec8eee4ab4e8ba943260 (patch)
tree42715b93ffa73c1a5058ef623bb770841366049a /libstdc++-v3
parent381dbd4a9564525d930737a790c9b7d31dfc181f (diff)
downloadgcc-0bb0d1d2880d562298eeec8eee4ab4e8ba943260.zip
gcc-0bb0d1d2880d562298eeec8eee4ab4e8ba943260.tar.gz
gcc-0bb0d1d2880d562298eeec8eee4ab4e8ba943260.tar.bz2
libstdc++: Make CTAD ignore pair(const T1&, const T2&) constructor [PR110853]
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>
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/include/bits/stl_pair.h2
-rw-r--r--libstdc++-v3/testsuite/20_util/pair/cons/110853.cc10
2 files changed, 11 insertions, 1 deletions
diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h
index 393f6a0..2de7439 100644
--- a/libstdc++-v3/include/bits/stl_pair.h
+++ b/libstdc++-v3/include/bits/stl_pair.h
@@ -445,7 +445,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/// 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)
diff --git a/libstdc++-v3/testsuite/20_util/pair/cons/110853.cc b/libstdc++-v3/testsuite/20_util/pair/cons/110853.cc
new file mode 100644
index 0000000..57ebfb8
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/pair/cons/110853.cc
@@ -0,0 +1,10 @@
+// { 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;