summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/debug
diff options
context:
space:
mode:
authorFrançois Dumont <fdumont@gcc.gnu.org>2020-01-21 19:12:29 +0100
committerFrançois Dumont <fdumont@gcc.gnu.org>2020-11-09 21:11:13 +0100
commit38b17c27ce5a8e0cc5baa14697d4b5542b91b9d1 (patch)
treeafdcc1232f79842a2546b0f785b551e7239e0926 /libstdc++-v3/include/debug
parent3a5f8d745f8e26d973218b088788f22ad197ca67 (diff)
libstdc++: Make _GLIBCXX_DEBUG checks constexpr compatible
libstdc++-v3/ChangeLog: * include/debug/assertions.h (__glibcxx_requires_non_empty_range): Remove __builtin_expect. (__glibcxx_requires_subscript): Likewise. (__glibcxx_requires_nonempty): Likewise. * include/debug/formatter.h (__check_singular): Add C++11 constexpr qualification. * include/debug/helper_functions.h (__check_singular): Likewise. Skip check if constant evaluated. (__valid_range): Do not skip check if constant evaluated. * include/debug/macros.h (_GLIBCXX_DEBUG_VERIFY_COND_AT): Add __builtin_expect. (_GLIBCXX_DEBUG_VERIFY_AT_F): Use __glibcxx_assert_1. * testsuite/21_strings/basic_string_view/element_access/char/back_constexpr_neg.cc: New test. * testsuite/21_strings/basic_string_view/element_access/char/constexpr.cc: New test. * testsuite/21_strings/basic_string_view/element_access/char/constexpr_neg.cc: New test. * testsuite/21_strings/basic_string_view/element_access/char/front_back_constexpr.cc: New test. * testsuite/21_strings/basic_string_view/element_access/char/front_constexpr_neg.cc: New test. * testsuite/21_strings/basic_string_view/element_access/wchar_t/back_constexpr_neg.cc: New test. * testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr.cc: New test. * testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr_neg.cc: New test. * testsuite/21_strings/basic_string_view/element_access/wchar_t/front_constexpr_neg.cc: New test. * testsuite/25_algorithms/lower_bound/debug/constexpr_partitioned_neg.cc: New test. * testsuite/25_algorithms/lower_bound/debug/constexpr_partitioned_pred_neg.cc: New test. * testsuite/25_algorithms/lower_bound/debug/constexpr_valid_range_neg.cc: New test. * testsuite/25_algorithms/lower_bound/debug/partitioned_neg.cc: New test. * testsuite/25_algorithms/lower_bound/debug/partitioned_pred_neg.cc: New test. * testsuite/25_algorithms/upper_bound/debug/constexpr_partitioned_neg.cc: New test. * testsuite/25_algorithms/upper_bound/debug/constexpr_partitioned_pred_neg.cc: New test. * testsuite/25_algorithms/upper_bound/debug/constexpr_valid_range_neg.cc: New test. * testsuite/25_algorithms/upper_bound/debug/partitioned_neg.cc: New test. * testsuite/25_algorithms/upper_bound/debug/partitioned_pred_neg.cc: New test.
Diffstat (limited to 'libstdc++-v3/include/debug')
-rw-r--r--libstdc++-v3/include/debug/assertions.h6
-rw-r--r--libstdc++-v3/include/debug/formatter.h3
-rw-r--r--libstdc++-v3/include/debug/helper_functions.h28
-rw-r--r--libstdc++-v3/include/debug/macros.h20
4 files changed, 26 insertions, 31 deletions
diff --git a/libstdc++-v3/include/debug/assertions.h b/libstdc++-v3/include/debug/assertions.h
index fb52e441424..16cf6bbe7ac 100644
--- a/libstdc++-v3/include/debug/assertions.h
+++ b/libstdc++-v3/include/debug/assertions.h
@@ -45,12 +45,12 @@
// Verify that [_First, _Last) forms a non-empty iterator range.
# define __glibcxx_requires_non_empty_range(_First,_Last) \
- __glibcxx_assert(__builtin_expect(_First != _Last, true))
+ __glibcxx_assert(_First != _Last)
# define __glibcxx_requires_subscript(_N) \
- __glibcxx_assert(__builtin_expect(_N < this->size(), true))
+ __glibcxx_assert(_N < this->size())
// Verify that the container is nonempty
# define __glibcxx_requires_nonempty() \
- __glibcxx_assert(__builtin_expect(!this->empty(), true))
+ __glibcxx_assert(!this->empty())
#endif
#ifdef _GLIBCXX_DEBUG
diff --git a/libstdc++-v3/include/debug/formatter.h b/libstdc++-v3/include/debug/formatter.h
index c4283fe6047..8734ed06cb5 100644
--- a/libstdc++-v3/include/debug/formatter.h
+++ b/libstdc++-v3/include/debug/formatter.h
@@ -72,7 +72,8 @@ namespace __gnu_debug
using std::type_info;
template<typename _Iterator>
- bool __check_singular(const _Iterator&);
+ _GLIBCXX_CONSTEXPR
+ bool __check_singular(_Iterator const&);
class _Safe_sequence_base;
diff --git a/libstdc++-v3/include/debug/helper_functions.h b/libstdc++-v3/include/debug/helper_functions.h
index 62d5309257f..281e9c7390e 100644
--- a/libstdc++-v3/include/debug/helper_functions.h
+++ b/libstdc++-v3/include/debug/helper_functions.h
@@ -120,15 +120,29 @@ namespace __gnu_debug
// We may have an iterator that derives from _Safe_iterator_base but isn't
// a _Safe_iterator.
template<typename _Iterator>
+ _GLIBCXX_CONSTEXPR
inline bool
__check_singular(_Iterator const& __x)
- { return __check_singular_aux(std::__addressof(__x)); }
+ {
+ return
+#ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
+ __builtin_is_constant_evaluated() ? false :
+#endif
+ __check_singular_aux(std::__addressof(__x));
+ }
/** Non-NULL pointers are nonsingular. */
template<typename _Tp>
+ _GLIBCXX_CONSTEXPR
inline bool
__check_singular(_Tp* const& __ptr)
- { return __ptr == 0; }
+ {
+ return
+#ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
+ __builtin_is_constant_evaluated() ? false :
+#endif
+ __ptr == 0;
+ }
/** We say that integral types for a valid range, and defer to other
* routines to realize what to do with integral types instead of
@@ -225,11 +239,6 @@ namespace __gnu_debug
__valid_range(_InputIterator __first, _InputIterator __last,
typename _Distance_traits<_InputIterator>::__type& __dist)
{
-#ifdef __cpp_lib_is_constant_evaluated
- if (std::is_constant_evaluated())
- // Detected by the compiler directly.
- return true;
-#endif
typedef typename std::__is_integer<_InputIterator>::__type _Integral;
return __valid_range_aux(__first, __last, __dist, _Integral());
}
@@ -253,11 +262,6 @@ namespace __gnu_debug
inline bool
__valid_range(_InputIterator __first, _InputIterator __last)
{
-#ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
- if (__builtin_is_constant_evaluated())
- // Detected by the compiler directly.
- return true;
-#endif
typedef typename std::__is_integer<_InputIterator>::__type _Integral;
return __valid_range_aux(__first, __last, _Integral());
}
diff --git a/libstdc++-v3/include/debug/macros.h b/libstdc++-v3/include/debug/macros.h
index ed606809a4d..ef4c76c747a 100644
--- a/libstdc++-v3/include/debug/macros.h
+++ b/libstdc++-v3/include/debug/macros.h
@@ -38,25 +38,15 @@
* the user error and where the error is reported.
*
*/
-#if 0 /* defined _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED */
-# define _GLIBCXX_DEBUG_VERIFY_COND_AT(_Cond,_ErrMsg,_File,_Line,_Func) \
- if (__builtin_is_constant_evaluated()) \
- /* FIXME: Compilation error here when !_Cond. */ \
- break; \
- if (! (_Cond)) \
+#define _GLIBCXX_DEBUG_VERIFY_COND_AT(_Cond,_ErrMsg,_File,_Line,_Func) \
+ if (__builtin_expect(!bool(_Cond), false)) \
__gnu_debug::_Error_formatter::_S_at(_File, _Line, _Func) \
._ErrMsg._M_error()
-#else
-# define _GLIBCXX_DEBUG_VERIFY_COND_AT(_Cond,_ErrMsg,_File,_Line,_Func) \
- if (! (_Cond)) \
- __gnu_debug::_Error_formatter::_S_at(_File, _Line, _Func) \
- ._ErrMsg._M_error()
-#endif
#define _GLIBCXX_DEBUG_VERIFY_AT_F(_Cond,_ErrMsg,_File,_Line,_Func) \
- do \
- { \
- _GLIBCXX_DEBUG_VERIFY_COND_AT(_Cond,_ErrMsg,_File,_Line,_Func); \
+ do { \
+ __glibcxx_assert_1(_Cond) \
+ { _GLIBCXX_DEBUG_VERIFY_COND_AT(_Cond,_ErrMsg,_File,_Line,_Func); } \
} while (false)
#define _GLIBCXX_DEBUG_VERIFY_AT(_Cond,_ErrMsg,_File,_Line) \