From 38b17c27ce5a8e0cc5baa14697d4b5542b91b9d1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Dumont?= Date: Tue, 21 Jan 2020 19:12:29 +0100 Subject: [PATCH] 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. --- libstdc++-v3/include/debug/assertions.h | 6 +-- libstdc++-v3/include/debug/formatter.h | 3 +- libstdc++-v3/include/debug/helper_functions.h | 28 +++++++----- libstdc++-v3/include/debug/macros.h | 20 +++------ .../element_access/char/back_constexpr_neg.cc | 35 +++++++++++++++ .../element_access/char/constexpr.cc | 31 +++++++++++++ .../element_access/char/constexpr_neg.cc | 34 ++++++++++++++ .../element_access/char/front_back_constexpr.cc | 41 +++++++++++++++++ .../element_access/char/front_constexpr_neg.cc | 35 +++++++++++++++ .../element_access/wchar_t/back_constexpr_neg.cc | 35 +++++++++++++++ .../element_access/wchar_t/constexpr.cc | 31 +++++++++++++ .../element_access/wchar_t/constexpr_neg.cc | 34 ++++++++++++++ .../element_access/wchar_t/front_constexpr_neg.cc | 35 +++++++++++++++ .../lower_bound/debug/constexpr_partitioned_neg.cc | 48 ++++++++++++++++++++ .../debug/constexpr_partitioned_pred_neg.cc | 38 ++++++++++++++++ .../lower_bound/debug/constexpr_valid_range_neg.cc | 52 ++++++++++++++++++++++ .../lower_bound/debug/partitioned_neg.cc | 46 +++++++++++++++++++ .../lower_bound/debug/partitioned_pred_neg.cc | 35 +++++++++++++++ .../upper_bound/debug/constexpr_partitioned_neg.cc | 48 ++++++++++++++++++++ .../debug/constexpr_partitioned_pred_neg.cc | 38 ++++++++++++++++ .../upper_bound/debug/constexpr_valid_range_neg.cc | 51 +++++++++++++++++++++ .../upper_bound/debug/partitioned_neg.cc | 46 +++++++++++++++++++ .../upper_bound/debug/partitioned_pred_neg.cc | 35 +++++++++++++++ 23 files changed, 774 insertions(+), 31 deletions(-) create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/back_constexpr_neg.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/constexpr.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/constexpr_neg.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/front_back_constexpr.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/front_constexpr_neg.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/back_constexpr_neg.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr_neg.cc create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/front_constexpr_neg.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/constexpr_partitioned_neg.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/constexpr_partitioned_pred_neg.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/constexpr_valid_range_neg.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/partitioned_neg.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/partitioned_pred_neg.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/constexpr_partitioned_neg.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/constexpr_partitioned_pred_neg.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/constexpr_valid_range_neg.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/partitioned_neg.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/partitioned_pred_neg.cc diff --git a/libstdc++-v3/include/debug/assertions.h b/libstdc++-v3/include/debug/assertions.h index fb52e44..16cf6bb 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 c4283fe..8734ed0 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 - 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 62d5309..281e9c7 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 + _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 + _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 ed60680..ef4c76c 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) \ diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/back_constexpr_neg.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/back_constexpr_neg.cc new file mode 100644 index 0000000..d5049ff --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/back_constexpr_neg.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++17 -D_GLIBCXX_ASSERTIONS" } +// { dg-do compile { target c++17 xfail *-*-* } } + +#include + +typedef std::string_view string_view_type; + +constexpr char +back() +{ + string_view_type s(""); + return s.back(); +} + +static_assert(back() != 'a'); // { dg-error "non-constant condition" } + +// { dg-prune-output "in 'constexpr' expansion" } +// { dg-prune-output "failed_assertion" } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/constexpr.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/constexpr.cc new file mode 100644 index 0000000..aa2a08e --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/constexpr.cc @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++17 } } + +#include + +constexpr char +test() +{ + typedef std::string_view string_view_type; + string_view_type s("abcd"); + return s[0]; +} + +static_assert(test() == 'a'); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/constexpr_neg.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/constexpr_neg.cc new file mode 100644 index 0000000..a302556 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/constexpr_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++17 -D_GLIBCXX_ASSERTIONS" } +// { dg-do compile { target c++17 xfail *-*-* } } + +#include + +constexpr char +test() +{ + typedef std::string_view string_view_type; + string_view_type s("abcd"); + return s[s.length()]; +} + +static_assert(test() == 0); // { dg-error "non-constant condition" } + +// { dg-prune-output "in 'constexpr' expansion" } +// { dg-prune-output "failed_assertion" } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/front_back_constexpr.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/front_back_constexpr.cc new file mode 100644 index 0000000..7ead45d --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/front_back_constexpr.cc @@ -0,0 +1,41 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++17 } } + +#include + +typedef std::string_view string_view_type; + +constexpr char +front() +{ + string_view_type s("abcd"); + return s.front(); +} + +static_assert(front() == 'a'); + +constexpr char +back() +{ + string_view_type s("abcd"); + return s.back(); +} + +static_assert(back() == 'd'); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/front_constexpr_neg.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/front_constexpr_neg.cc new file mode 100644 index 0000000..8fad31a --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/front_constexpr_neg.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++17 -D_GLIBCXX_ASSERTIONS" } +// { dg-do compile { target c++17 xfail *-*-* } } + +#include + +typedef std::string_view string_view_type; + +constexpr char +front() +{ + string_view_type s(""); + return s.front(); +} + +static_assert(front() != 'a'); // { dg-error "non-constant condition" } + +// { dg-prune-output "in 'constexpr' expansion" } +// { dg-prune-output "failed_assertion" } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/back_constexpr_neg.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/back_constexpr_neg.cc new file mode 100644 index 0000000..0500a2d --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/back_constexpr_neg.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++17 -D_GLIBCXX_ASSERTIONS" } +// { dg-do compile { target c++17 xfail *-*-* } } + +#include + +typedef std::wstring_view string_view_type; + +constexpr wchar_t +back() +{ + string_view_type s(L""); + return s.back(); +} + +static_assert(back() != L'a'); // { dg-error "non-constant condition" } + +// { dg-prune-output "in 'constexpr' expansion" } +// { dg-prune-output "failed_assertion" } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr.cc new file mode 100644 index 0000000..f417162 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr.cc @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++17 } } + +#include + +constexpr wchar_t +test() +{ + typedef std::wstring_view string_view_type; + string_view_type s(L"abcd"); + return s[0]; +} + +static_assert(test() == L'a'); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr_neg.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr_neg.cc new file mode 100644 index 0000000..299a73b --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr_neg.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++17 -D_GLIBCXX_ASSERTIONS" } +// { dg-do compile { target c++17 xfail *-*-* } } + +#include + +constexpr wchar_t +test() +{ + typedef std::wstring_view string_view_type; + string_view_type s(L"abcd"); + return s[4]; +} + +static_assert(test() == 0); // { dg-error "non-constant condition" } + +// { dg-prune-output "in 'constexpr' expansion" } +// { dg-prune-output "failed_assertion" } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/front_constexpr_neg.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/front_constexpr_neg.cc new file mode 100644 index 0000000..009b4e4 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/front_constexpr_neg.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++17 -D_GLIBCXX_ASSERTIONS" } +// { dg-do compile { target c++17 xfail *-*-* } } + +#include + +typedef std::wstring_view string_view_type; + +constexpr wchar_t +front() +{ + string_view_type s(L""); + return s.front(); +} + +static_assert(front() != L'a'); // { dg-error "non-constant condition" } + +// { dg-prune-output "in 'constexpr' expansion" } +// { dg-prune-output "failed_assertion" } diff --git a/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/constexpr_partitioned_neg.cc b/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/constexpr_partitioned_neg.cc new file mode 100644 index 0000000..ee4b19e --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/constexpr_partitioned_neg.cc @@ -0,0 +1,48 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a xfail *-*-* } } +// { dg-require-debug-mode { } } + +#include +#include + +struct A +{ + int _i; + + constexpr bool + operator<(const A& a) const + { return _i < a._i; } +}; + +constexpr bool +test() +{ + constexpr std::array ca0{{0, 1, 2, 3, 4, 5, 6, 5, 8, 9, 10, 11}}; + + constexpr A a6{ 6 }; + const auto it = std::lower_bound(ca0.begin(), ca0.end(), a6); + + return true; +} + +static_assert(test()); // { dg-error "" } + +// { dg-prune-output "failed_assertion" } +// { dg-prune-output "in 'constexpr'" } diff --git a/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/constexpr_partitioned_pred_neg.cc b/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/constexpr_partitioned_pred_neg.cc new file mode 100644 index 0000000..01eb38a --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/constexpr_partitioned_pred_neg.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a xfail *-*-* } } +// { dg-require-debug-mode { } } + +#include +#include + +constexpr bool +test() +{ + constexpr std::array ca0{{0, 1, 2, 3, 4, 5, 6, 5, 8, 9, 10, 11}}; + + const auto it = std::lower_bound(ca0.begin(), ca0.end(), 6, std::less()); + + return true; +} + +static_assert(test()); // { dg-error "" } + +// { dg-prune-output "failed_assertion" } +// { dg-prune-output "in 'constexpr'" } diff --git a/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/constexpr_valid_range_neg.cc b/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/constexpr_valid_range_neg.cc new file mode 100644 index 0000000..787352a --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/constexpr_valid_range_neg.cc @@ -0,0 +1,52 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a xfail *-*-* } } +// { dg-require-debug-mode { } } + +#include +#include + +constexpr bool +test1() +{ + constexpr std::array ca0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}; + + const auto outbb = std::lower_bound(ca0.end(), ca0.begin(), 6); + + return true; +} + +static_assert(test1()); // { dg-error "" } + +constexpr bool +test2() +{ + constexpr std::array ca0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}; + + const auto outcc = std::lower_bound(ca0.end(), ca0.begin(), 6, + std::less()); + + return true; +} + +static_assert(test2()); // { dg-error "" } + +// { dg-prune-output "failed_assertion" } +// { dg-prune-output "in 'constexpr'" } + diff --git a/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/partitioned_neg.cc b/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/partitioned_neg.cc new file mode 100644 index 0000000..cdf4a3a --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/partitioned_neg.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do run { xfail *-*-* } } +// { dg-require-debug-mode "" } + +#include + +struct A +{ + A(int i) : _i(i) + { } + + int _i; + + bool + operator<(const A& a) const + { return _i < a._i; } +}; + +void test01() +{ + A as[] = { 0, 1, 2, 0, 2, 3 }; + std::lower_bound(as, as + 6, A(1)); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/partitioned_pred_neg.cc b/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/partitioned_pred_neg.cc new file mode 100644 index 0000000..9eda304 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/lower_bound/debug/partitioned_pred_neg.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do run { xfail *-*-* } } +// { dg-require-debug-mode "" } + +#include + +void test01() +{ + int as[] = { 0, 1, 0, 2, 3 }; + std::lower_bound(as, as + 5, 1, std::less()); +} + + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/constexpr_partitioned_neg.cc b/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/constexpr_partitioned_neg.cc new file mode 100644 index 0000000..716cdfa --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/constexpr_partitioned_neg.cc @@ -0,0 +1,48 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a xfail *-*-* } } +// { dg-require-debug-mode { } } + +#include +#include + +struct A +{ + int _i; + + constexpr bool + operator<(const A& a) const + { return _i == a._i; } +}; + +constexpr bool +test() +{ + constexpr std::array ca0{{0, 1, 2, 3, 4, 5, 6, 5, 8, 9, 10, 11}}; + + constexpr A a6{ 6 }; + const auto it = std::upper_bound(ca0.begin(), ca0.end(), a6); + + return true; +} + +static_assert(test()); // { dg-error "" } + +// { dg-prune-output "failed_assertion" } +// { dg-prune-output "in 'constexpr'" } diff --git a/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/constexpr_partitioned_pred_neg.cc b/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/constexpr_partitioned_pred_neg.cc new file mode 100644 index 0000000..2307e17 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/constexpr_partitioned_pred_neg.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a xfail *-*-* } } +// { dg-require-debug-mode { } } + +#include +#include + +constexpr bool +test() +{ + constexpr std::array ca0{{0, 1, 2, 3, 4, 5, 7, 6, 8, 9, 10, 11}}; + + const auto it = std::upper_bound(ca0.begin(), ca0.end(), 6, std::less()); + + return true; +} + +static_assert(test()); // { dg-error "" } + +// { dg-prune-output "failed_assertion" } +// { dg-prune-output "in 'constexpr'" } diff --git a/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/constexpr_valid_range_neg.cc b/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/constexpr_valid_range_neg.cc new file mode 100644 index 0000000..bcce2c4 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/constexpr_valid_range_neg.cc @@ -0,0 +1,51 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a xfail *-*-* } } +// { dg-require-debug-mode { } } + +#include +#include + +constexpr bool +test1() +{ + constexpr std::array ca0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}; + + const auto outbb = std::upper_bound(ca0.end(), ca0.begin(), 6); + + return true; +} + +static_assert(test1()); // { dg-error "" } + +constexpr bool +test2() +{ + constexpr std::array ca0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}; + + const auto outcc = std::upper_bound(ca0.end(), ca0.begin(), 6, + std::less()); + + return true; +} + +static_assert(test2()); // { dg-error "" } + +// { dg-prune-output "failed_assertion" } +// { dg-prune-output "in 'constexpr'" } diff --git a/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/partitioned_neg.cc b/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/partitioned_neg.cc new file mode 100644 index 0000000..cbae81a --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/partitioned_neg.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do run { xfail *-*-* } } +// { dg-require-debug-mode "" } + +#include + +struct A +{ + A(int i) : _i(i) + { } + + int _i; + + bool + operator<(const A& a) const + { return _i < a._i; } +}; + +void test01() +{ + A as[] = { 0, 2, 1, 3, 4, 5 }; + std::upper_bound(as, as + 6, A(1)); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/partitioned_pred_neg.cc b/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/partitioned_pred_neg.cc new file mode 100644 index 0000000..5a42c2b --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/upper_bound/debug/partitioned_pred_neg.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do run { xfail *-*-* } } +// { dg-require-debug-mode "" } + +#include + +void test01() +{ + int as[] = { 0, 2, 1, 3, 4 }; + std::upper_bound(as, as + 5, 1, std::less()); +} + + +int +main() +{ + test01(); + return 0; +} -- 2.7.4