summaryrefslogtreecommitdiffstats
path: root/libcxx/include/__tree
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2017-01-13 22:02:08 +0000
committerEric Fiselier <eric@efcs.ca>2017-01-13 22:02:08 +0000
commitb1e7a12ee89ffcf50d0b18f8c6da7423604ea9d8 (patch)
tree757d7fbfc219efa1b5ddbfbd9956ea8435fbabec /libcxx/include/__tree
parent4e8d1475bdb6fdecd938678e0e0a8e0ab543ffc1 (diff)
downloadbcm5719-llvm-b1e7a12ee89ffcf50d0b18f8c6da7423604ea9d8.tar.gz
bcm5719-llvm-b1e7a12ee89ffcf50d0b18f8c6da7423604ea9d8.zip
Add _LIBCPP_DIAGNOSE_WARNING and _LIBCPP_DIAGNOSE_ERROR macros.
Clang recently added a `diagnose_if(cond, msg, type)` attribute which can be used to generate diagnostics when `cond` is a constant expression that evaluates to true. Otherwise no attribute has no effect. This patch adds _LIBCPP_DIAGNOSE_ERROR/WARNING macros which use this new attribute. Additionally this patch implements a diagnostic message when a non-const-callable comparator is given to a container. Note: For now the warning version of the diagnostic is useless within libc++ since warning diagnostics are suppressed by the system header pragma. I'm going to work on fixing this. llvm-svn: 291961
Diffstat (limited to 'libcxx/include/__tree')
-rw-r--r--libcxx/include/__tree34
1 files changed, 33 insertions, 1 deletions
diff --git a/libcxx/include/__tree b/libcxx/include/__tree
index dd32f700586..3bc02073411 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -41,6 +41,10 @@ template <class _Key, class _Value>
struct __value_type;
#endif
+template <class _Key, class _CP, class _Compare,
+ bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value>
+class __map_value_compare;
+
template <class _Allocator> class __map_node_destructor;
template <class _TreeIterator> class _LIBCPP_TEMPLATE_VIS __map_iterator;
template <class _TreeIterator> class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
@@ -955,6 +959,30 @@ private:
};
+#ifndef _LIBCPP_CXX03_LANG
+template <class _Tp, class _Compare, class _Allocator>
+struct __diagnose_tree_helper {
+ static constexpr bool __trigger_diagnostics()
+ _LIBCPP_DIAGNOSE_WARNING(!__is_const_comparable<_Compare, _Tp>::value,
+ "the specified comparator type does not provide a const call operator")
+ { return true; }
+};
+
+template <class _Key, class _Value, class _KeyComp, class _Alloc>
+struct __diagnose_tree_helper<
+ __value_type<_Key, _Value>,
+ __map_value_compare<_Key, __value_type<_Key, _Value>, _KeyComp>,
+ _Alloc
+>
+{
+ static constexpr bool __trigger_diagnostics()
+ _LIBCPP_DIAGNOSE_WARNING(!__is_const_comparable<_KeyComp, _Key>::value,
+ "the specified comparator type does not provide a const call operator")
+ { return true; }
+};
+
+#endif
+
template <class _Tp, class _Compare, class _Allocator>
class __tree
{
@@ -1787,7 +1815,11 @@ __tree<_Tp, _Compare, _Allocator>::~__tree()
{
static_assert((is_copy_constructible<value_compare>::value),
"Comparator must be copy-constructible.");
- destroy(__root());
+#ifndef _LIBCPP_CXX03_LANG
+ static_assert((__diagnose_tree_helper<_Tp, _Compare, _Allocator>::
+ __trigger_diagnostics()), "");
+#endif
+ destroy(__root());
}
template <class _Tp, class _Compare, class _Allocator>
OpenPOWER on IntegriCloud