From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id B33A73858004; Sun, 8 Nov 2020 14:06:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B33A73858004 Received: by mail-wr1-x436.google.com with SMTP id p1so6022459wrf.12; Sun, 08 Nov 2020 06:06:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=E8S6gsH2V8xMSUQDNXEPgNdyeDtjuS/SVe5sZSdnanM=; b=mgVgijC5NuOIZS44XIO303cSQWuXX6PgQA8/lCGTyP+NHYueAc8C79tpNXS0KJLZr8 K3MwksM5pjbODNKxAf/KiY0F3tYJzHVm0JkXUYaIl+RJF0EqGTLrByrrSomb5C1U43UM Ra3Htp7T6U46/setvTrNvMJM1vVYtIix1Dsb3iBD2rm2fpAZF9vpVAuZrVYNcBOTXZzR CZ4yfyhQNWKe2DUYKKbiW/Foskpgr/af2XfI8HP16KLrH7lLdqsrpwbQs+vhgvFtG+ZD xPaNAvD1lFCpkcMroeQXtmEHcAj7cf9/vYW3iHX1y1IbMrrVr0YNvne1z6k0zdK56Ooq 3VaA== X-Gm-Message-State: AOAM531hEh/yjPBN8iRoClM8fcq4g5H+yDs0zR4160aDQU4PJazbLP6F wkvcxDOaIFZwBSE/dpcz92XpSVpuYgc= X-Google-Smtp-Source: ABdhPJw6/ZSXRC2UcXClwX/ZwkCXAfkrIsEFafIoBQGRslSJMYRIdNramSfLMFYuf57piFzzBXM1Sg== X-Received: by 2002:a5d:660c:: with SMTP id n12mr12912345wru.401.1604844368238; Sun, 08 Nov 2020 06:06:08 -0800 (PST) Received: from ?IPv6:2a01:e0a:1dc:b1c0:81ea:af76:50ae:ab84? ([2a01:e0a:1dc:b1c0:81ea:af76:50ae:ab84]) by smtp.googlemail.com with ESMTPSA id r18sm10994571wrj.50.2020.11.08.06.06.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 Nov 2020 06:06:07 -0800 (PST) To: "libstdc++@gcc.gnu.org" , gcc-patches From: =?UTF-8?Q?Fran=c3=a7ois_Dumont?= Subject: [PATCH] 1/2 Make _GLIBCXX_DEBUG checks constexpr compatible Message-ID: <60e247d6-f0b5-7613-34ea-2810e84d9ca1@gmail.com> Date: Sun, 8 Nov 2020 15:06:06 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------069356E4BA90BDA79FA216B0" Content-Language: fr X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Nov 2020 14:06:14 -0000 This is a multi-part message in MIME format. --------------069356E4BA90BDA79FA216B0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Now that __glibcxx_assert is constexpr compatible we can do the same for the _GLIBCXX_DEBUG equivalent. I had also try to do the same on my own so this patch contains the string_view tests I had written when doing so. I plan to activate some _GLIBCXX_DEBUG checks when _GLIBCXX_ASSERTIONS is defined but only the contant time checks. Is it ok to run checks like __check_partitioned_lower in constexpr ?     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. Tested under Linux x86_64. Ok to commit ? François --------------069356E4BA90BDA79FA216B0 Content-Type: text/x-patch; charset=UTF-8; name="debug_constexpr.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="debug_constexpr.patch" 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 - 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 + _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 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) \ 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 00000000000..d5049ff246c --- /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 00000000000..aa2a08ebe83 --- /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 00000000000..a302556866c --- /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 00000000000..7ead45ddcf6 --- /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 00000000000..8fad31a07dd --- /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 00000000000..0500a2de600 --- /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 00000000000..f4171628e9f --- /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 00000000000..299a73b8c8e --- /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 00000000000..009b4e41a73 --- /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 00000000000..ee4b19e9e7b --- /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 00000000000..01eb38a8807 --- /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 00000000000..787352aa94b --- /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 00000000000..cdf4a3a2ed4 --- /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 00000000000..9eda3046745 --- /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 00000000000..716cdfa85ae --- /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 00000000000..2307e17bfa5 --- /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 00000000000..bcce2c48a1f --- /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 00000000000..cbae81a08f3 --- /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 00000000000..5a42c2b32c0 --- /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; +} --------------069356E4BA90BDA79FA216B0--