diff --git a/libcxx/include/map b/libcxx/include/map --- a/libcxx/include/map +++ b/libcxx/include/map @@ -907,7 +907,6 @@ typedef value_type& reference; typedef const value_type& const_reference; - static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); static_assert((is_same::value), "Allocator::value_type must be same type as value_type"); @@ -1085,6 +1084,11 @@ insert(__m.begin(), __m.end()); } + _LIBCPP_INLINE_VISIBILITY + ~map() { + static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); + } + _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __tree_.begin();} _LIBCPP_INLINE_VISIBILITY @@ -1638,7 +1642,6 @@ typedef value_type& reference; typedef const value_type& const_reference; - static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); static_assert((is_same::value), "Allocator::value_type must be same type as value_type"); @@ -1817,6 +1820,11 @@ insert(__m.begin(), __m.end()); } + _LIBCPP_INLINE_VISIBILITY + ~multimap() { + static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); + } + _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __tree_.begin();} _LIBCPP_INLINE_VISIBILITY diff --git a/libcxx/include/set b/libcxx/include/set --- a/libcxx/include/set +++ b/libcxx/include/set @@ -450,7 +450,6 @@ typedef value_type& reference; typedef const value_type& const_reference; - static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); static_assert((is_same::value), "Allocator::value_type must be same type as value_type"); @@ -596,6 +595,11 @@ } #endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + ~set() { + static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); + } + _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __tree_.begin();} _LIBCPP_INLINE_VISIBILITY @@ -938,7 +942,6 @@ typedef value_type& reference; typedef const value_type& const_reference; - static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); static_assert((is_same::value), "Allocator::value_type must be same type as value_type"); @@ -1083,6 +1086,11 @@ } #endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + ~multiset() { + static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); + } + _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __tree_.begin();} _LIBCPP_INLINE_VISIBILITY diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map --- a/libcxx/include/unordered_map +++ b/libcxx/include/unordered_map @@ -852,7 +852,6 @@ typedef const value_type& const_reference; static_assert((is_same::value), "Invalid allocator::value_type"); - static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), ""); private: typedef __hash_value_type __value_type; @@ -963,7 +962,11 @@ const allocator_type& __a) : unordered_map(__il, __n, __hf, key_equal(), __a) {} #endif - // ~unordered_map() = default; + _LIBCPP_INLINE_VISIBILITY + ~unordered_map() { + static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), ""); + } + _LIBCPP_INLINE_VISIBILITY unordered_map& operator=(const unordered_map& __u) { @@ -1678,7 +1681,6 @@ typedef const value_type& const_reference; static_assert((is_same::value), "Invalid allocator::value_type"); - static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), ""); private: typedef __hash_value_type __value_type; @@ -1787,7 +1789,11 @@ const allocator_type& __a) : unordered_multimap(__il, __n, __hf, key_equal(), __a) {} #endif - // ~unordered_multimap() = default; + _LIBCPP_INLINE_VISIBILITY + ~unordered_multimap() { + static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), ""); + } + _LIBCPP_INLINE_VISIBILITY unordered_multimap& operator=(const unordered_multimap& __u) { diff --git a/libcxx/include/unordered_set b/libcxx/include/unordered_set --- a/libcxx/include/unordered_set +++ b/libcxx/include/unordered_set @@ -390,7 +390,6 @@ typedef const value_type& const_reference; static_assert((is_same::value), "Invalid allocator::value_type"); - static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), ""); private: typedef __hash_table __table; @@ -486,7 +485,11 @@ : unordered_set(__il, __n, __hf, key_equal(), __a) {} #endif #endif // _LIBCPP_CXX03_LANG - // ~unordered_set() = default; + _LIBCPP_INLINE_VISIBILITY + ~unordered_set() { + static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), ""); + } + _LIBCPP_INLINE_VISIBILITY unordered_set& operator=(const unordered_set& __u) { @@ -990,7 +993,6 @@ typedef const value_type& const_reference; static_assert((is_same::value), "Invalid allocator::value_type"); - static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), ""); private: typedef __hash_table __table; @@ -1084,7 +1086,11 @@ : unordered_multiset(__il, __n, __hf, key_equal(), __a) {} #endif #endif // _LIBCPP_CXX03_LANG - // ~unordered_multiset() = default; + _LIBCPP_INLINE_VISIBILITY + ~unordered_multiset() { + static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), ""); + } + _LIBCPP_INLINE_VISIBILITY unordered_multiset& operator=(const unordered_multiset& __u) { diff --git a/libcxx/test/libcxx/containers/associative/non_const_comparator.pass.cpp b/libcxx/test/libcxx/containers/associative/non_const_comparator.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/containers/associative/non_const_comparator.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 +// REQUIRES: verify-support + +// Test that libc++ does not generate a warning diagnostic about the comparator +// too early for containers of incomplete types. +// +// See PR41360. + +#include +#include +#include + + +template