https://gcc.gnu.org/g:2f744df601b298e31dcdb49316da93f0ce1f00b7
commit r14-10917-g2f744df601b298e31dcdb49316da93f0ce1f00b7 Author: Jonathan Wakely <jwak...@redhat.com> Date: Fri Nov 8 13:58:23 2024 +0000 libstdc++: Do not define _Insert_base::try_emplace before C++17 This is not a reserved name in C++11 and C++14, so must not be defined. Also use the appropriate feature test macros for the try_emplace members of the Debug Mode maps. libstdc++-v3/ChangeLog: * include/bits/hashtable_policy.h (_Insert_base::try_emplace): Do not define for C++11 and C++14. * include/debug/map.h (try_emplace): Use feature test macro. * include/debug/unordered_map (try_emplace): Likewise. * testsuite/17_intro/names.cc: Define try_emplace before C++17. (cherry picked from commit b66a57c0ad300b293ebd366bc29f44f2ddb65c69) Diff: --- libstdc++-v3/include/bits/hashtable_policy.h | 2 ++ libstdc++-v3/include/debug/map.h | 2 +- libstdc++-v3/include/debug/unordered_map | 2 +- libstdc++-v3/testsuite/17_intro/names.cc | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/bits/hashtable_policy.h b/libstdc++-v3/include/bits/hashtable_policy.h index 26def24f24e6..68ec8d9470a7 100644 --- a/libstdc++-v3/include/bits/hashtable_policy.h +++ b/libstdc++-v3/include/bits/hashtable_policy.h @@ -966,6 +966,7 @@ namespace __detail return __h._M_insert(__hint, __v, __node_gen, __unique_keys{}); } +#ifdef __glibcxx_unordered_map_try_emplace // C++ >= 17 && HOSTED template<typename _KType, typename... _Args> std::pair<iterator, bool> try_emplace(const_iterator, _KType&& __k, _Args&&... __args) @@ -987,6 +988,7 @@ namespace __detail __node._M_node = nullptr; return { __it, true }; } +#endif void insert(initializer_list<value_type> __l) diff --git a/libstdc++-v3/include/debug/map.h b/libstdc++-v3/include/debug/map.h index d0e398f0fd97..5323a2b0d950 100644 --- a/libstdc++-v3/include/debug/map.h +++ b/libstdc++-v3/include/debug/map.h @@ -344,7 +344,7 @@ namespace __debug } -#if __cplusplus > 201402L +#ifdef __glibcxx_map_try_emplace // C++ >= 17 && HOSTED template <typename... _Args> pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args) diff --git a/libstdc++-v3/include/debug/unordered_map b/libstdc++-v3/include/debug/unordered_map index 8a969d817402..1700da16c0f3 100644 --- a/libstdc++-v3/include/debug/unordered_map +++ b/libstdc++-v3/include/debug/unordered_map @@ -440,7 +440,7 @@ namespace __debug _M_check_rehashed(__bucket_count); } -#if __cplusplus > 201402L +#ifdef __glibcxx_unordered_map_try_emplace // C++ >= 17 && HOSTED template <typename... _Args> pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args) diff --git a/libstdc++-v3/testsuite/17_intro/names.cc b/libstdc++-v3/testsuite/17_intro/names.cc index 9b0ffcb50b2e..ab12641b14df 100644 --- a/libstdc++-v3/testsuite/17_intro/names.cc +++ b/libstdc++-v3/testsuite/17_intro/names.cc @@ -136,6 +136,8 @@ // <charconv> defines to_chars_result::ptr and to_chars_result::ec #define ec ( #define ptr ( +// <map> and <unordered_map> define try_emplace +#define try_emplace ( #endif // These clash with newlib so don't use them.