From patchwork Tue Jul 7 10:18:31 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Kami=C5=84ski?= X-Patchwork-Id: 138646 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 578564BA5436 for ; Tue, 7 Jul 2026 10:22:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 578564BA5436 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dx7zD9ga X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 3BA274BA2E2D for ; Tue, 7 Jul 2026 10:21:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3BA274BA2E2D Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3BA274BA2E2D Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783419661; cv=none; b=DRTkKYz17THRr6vJM5V8VLpc4w2P98c0zEi4cGgKHFBKbHCbWyEPCvDVAvxKITZrZnsowz4D+9LgTBoAkxFP21bP98MoDAItjsaztQAMKTz0aW204Lir/dzYgxBerB5hNt+60Xz9kfpuJiTjchxAGWkz/5LkxyyXIM+qpZDDsVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783419661; c=relaxed/simple; bh=CUdyxGfCHn+2ie5g7NiENolsI356i2RrRh271GSBZx0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=a4JailtsnEGv8EjDlsDkRhavvDRuQOA5imevME4t7EI/zK1jEWH8N/5vRipiIc6uTg+CWN9JIztRggzTNfB8Ug+TbnGFFuyqgophSq0v3QW/URiDRGPzIxv8vwCjavaJgWTtU/Rh8+kcHYbsaePwcYTPsd9N2VmRf5w7dAY4MtU= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dx7zD9ga DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3BA274BA2E2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783419660; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=D0Y4Tn2kZ+IgaNCRNXys6NY68XsK3qdoAPhui0XjIKA=; b=dx7zD9gaah9e/q7TqbYuwfy+mxuq4aI4DkdfRpBKuSlc2SZtvOg4MBxGCrTTQ3+hpuZsD6 fLb8THBvgRm2byXiefFeGiVqwOP2PUvZrFPXJTQyMd+CAAgoWvHCjtqqH9/1ZPCIBy9fFT 7PdyBkBYzYp4nNHL3ENVted3Go5qkxk= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-104-vHGTdeSVNeGcG7hBy6v58A-1; Tue, 07 Jul 2026 06:20:59 -0400 X-MC-Unique: vHGTdeSVNeGcG7hBy6v58A-1 X-Mimecast-MFC-AGG-ID: vHGTdeSVNeGcG7hBy6v58A_1783419658 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 47CE01956064; Tue, 7 Jul 2026 10:20:58 +0000 (UTC) Received: from localhost (unknown [10.44.49.91]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7D22D3000C00; Tue, 7 Jul 2026 10:20:57 +0000 (UTC) From: =?utf-8?q?Tomasz_Kami=C5=84ski?= To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 1/2] libstdc++: Validate user-provided stride values for layout_stride. Date: Tue, 7 Jul 2026 12:18:31 +0200 Message-ID: <20260707102055.512253-1-tkaminsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: CgMnUQ7RdDmeRregD2mKH3JgULivugK781Rr0ytzgtA_1783419658 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Converting the __strides values using __index_type_cast asserts that they are non-negative and each value is representable as index_type. libstdc++-v3/ChangeLog: * include/std/mdspan (layout_stride::mapping::mapping(const extent_type&, span<...>): Convert strides using __index_type_cast, which bring asserts for negative and unrepresentable values. * testsuite/23_containers/mdspan/layouts/stride_neg.cc: New test. --- Tested on x86_64-linux locally. OK for trunk? libstdc++-v3/include/std/mdspan | 3 +- .../mdspan/layouts/stride_neg.cc | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/23_containers/mdspan/layouts/stride_neg.cc diff --git a/libstdc++-v3/include/std/mdspan b/libstdc++-v3/include/std/mdspan index f5556f35fa1..5e1c4d8b1a4 100644 --- a/libstdc++-v3/include/std/mdspan +++ b/libstdc++-v3/include/std/mdspan @@ -1891,7 +1891,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _M_extents(__exts) { for (size_t __i = 0; __i < extents_type::rank(); ++__i) - _M_strides[__i] = index_type(as_const(__strides[__i])); + _M_strides[__i] + = __mdspan::__index_type_cast(__strides[__i]); } template diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/stride_neg.cc b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/stride_neg.cc new file mode 100644 index 00000000000..153560bc82f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/stride_neg.cc @@ -0,0 +1,31 @@ +// { dg-do compile { target c++23 } } +#include + +#include "../layout_traits.h" +#include + +constexpr size_t dyn = std::dynamic_extent; + +constexpr bool +test_stride_overflow() +{ + auto exts = std::extents(1, 3); + auto n = size_t(1) << 9; + auto m = std::layout_stride::mapping(exts, std::array{n, 1zu}); // { dg-error "expansion of" } + (void) m; + return true; +} +static_assert(test_stride_overflow()); // { dg-error "expansion of" } + +constexpr bool +test_stride_negative() +{ + auto exts = std::extents(1, 3); + auto m = std::layout_stride::mapping(exts, std::array{1, -4}); // { dg-error "expansion of" } + (void) m; + return true; +} +static_assert(test_stride_negative()); // { dg-error "expansion of" } + +// { dg-prune-output "non-constant condition for static assertion" } +// { dg-prune-output "__glibcxx_assert_fail()" } From patchwork Tue Jul 7 10:18:32 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Kami=C5=84ski?= X-Patchwork-Id: 138645 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C42184BA23C3 for ; Tue, 7 Jul 2026 10:22:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C42184BA23C3 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fNB7Rc7L X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 5CBDC4BA2E19 for ; Tue, 7 Jul 2026 10:21:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5CBDC4BA2E19 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5CBDC4BA2E19 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783419665; cv=none; b=MsDF9btw7ygp6arslbqhk37FbfxXQtFpkatOHoA+KCdCH44I5NVCVG5I4s1/qOcCRwoAJz3F//V/zMji8ekp0aK9Ql9NbRCr9H7LHdTYsaNk5+FLaNPr/EXdI6w8Tj9cSRVqSFyQW5Gc71SOpIuaZLAxoVtb1oLRQ17P/yRk4N4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783419665; c=relaxed/simple; bh=MyjgIcuvmATBY26F4YUHUuQS08ZT3lBTw8Rd4/0jI04=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=K9On/Ml++X63iMaklBLAMXayLo06avkQ3lJhXp8+EgxYjewspCzCxoe2rKgRRtQWHE6aKrHJfO8U03d2RBqkxA2L49gUpOd79FJdshkWvqxW7cv6Vxm1+cSW/4f8mIwe7TAAr/fHhiknRg4CDOsp2eI0P6e/IV0T+b0x0SJ1pH4= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fNB7Rc7L DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5CBDC4BA2E19 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783419665; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=22LWBB4yuwESB6PgEMPdvAihNUM+YIfftQB0ZfLzPOw=; b=fNB7Rc7Loxa2qZlzbO+W+Z1CMWz0ncPMuxc3iQiHXROyLQXHU8Oz9SPe+0lrWI1XUwr44u WD17AfpxhmWq+fiMJP4lttTl1oced7b05i9Fx4Oe/J7XGbRe3zqKZPMZcWbXNqPTE4tmxX NSBWAcb9jUqyv+IpvXKmn+xqsMSOyBM= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-164-Lt9DMfufNeqc-UkU66coFw-1; Tue, 07 Jul 2026 06:21:01 -0400 X-MC-Unique: Lt9DMfufNeqc-UkU66coFw-1 X-Mimecast-MFC-AGG-ID: Lt9DMfufNeqc-UkU66coFw_1783419661 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B5ADC1954B2E; Tue, 7 Jul 2026 10:21:00 +0000 (UTC) Received: from localhost (unknown [10.44.49.91]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0789E19560A3; Tue, 7 Jul 2026 10:20:59 +0000 (UTC) From: =?utf-8?q?Tomasz_Kami=C5=84ski?= To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] libstdc++: Assert that produced layout_stride::mapping is unique. Date: Tue, 7 Jul 2026 12:18:32 +0200 Message-ID: <20260707102055.512253-2-tkaminsk@redhat.com> In-Reply-To: <20260707102055.512253-1-tkaminsk@redhat.com> References: <20260707102055.512253-1-tkaminsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: kvA4vd02PLZbL3BrWbzITaMRiBqdcre3p4RlPahdPJo_1783419661 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org This add an assertions checking if the combination of strides and extents passed to layout_stride::mapping is unique. To avoid excessive performance impact, in non-debug mode only checks that are are O(rank) (i.e. similar cost as operator()) are performed. To achieve that, for the ranks greater or equal, we perform two separate checks: * required_span_size() > mdspan::__size(_M_extents) - this is required by not sufficient condition, that is O(rank) and is always performed. * building an permutation using selection-sort based algorithm, this is O(rank^2) and is performed only in debug modes. The check for non-zero stride values (performed for all non-zero ranks) is done only if the size of the multidimensional index space is not empty. This follows the resolution of LWG4603, and provides consistent behavior for constructing layout_stride mapping from layout_left/right directly or from strides extracted from it. libstdc++-v3/ChangeLog: * include/std/mdspan (layout_stride::mapping::_M_check_unique): Define. (layout_stride::mapping(const extents_type&, span<....>): Add __glibcxx_assert on _M_check_unique. * testsuite/23_containers/mdspan/layouts/stride_neg.cc: Test for the new added assertions. --- Are we OK with full detection only for ranks <= 2 and some subset of problematic layouts with rank >= 3? I think this is good sweet spot. But I see how some may argue for consistency here, but then I would put unique dection only in debug for all ranks. Tested on x86_64-linux locally. *mdspan* test passed in all standard modes and with _GLIBCXX_DEBUG. OK for trunk? libstdc++-v3/include/std/mdspan | 83 ++++++++++++++++++- .../mdspan/layouts/stride_neg.cc | 42 ++++++++++ 2 files changed, 123 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/std/mdspan b/libstdc++-v3/include/std/mdspan index 5e1c4d8b1a4..69dbe091884 100644 --- a/libstdc++-v3/include/std/mdspan +++ b/libstdc++-v3/include/std/mdspan @@ -1893,6 +1893,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION for (size_t __i = 0; __i < extents_type::rank(); ++__i) _M_strides[__i] = __mdspan::__index_type_cast(__strides[__i]); + + __glibcxx_assert(_M_check_unique()); } template @@ -2027,6 +2029,85 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } private: + using _Strides = typename __array_traits::_Type; + + constexpr bool + _M_check_unique() const + { + constexpr size_t __rank = extents_type::rank(); + if constexpr (__rank == 0) + return true; + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 4603. `layout_stride` should accept zero strides for empty `extents` + else if (__mdspan::__empty(_M_extents)) + return true; + else if constexpr (__rank == 1) + return _M_strides[0] > 0; + else if (__mdspan::__contains_zero(_M_strides)) + return false; + else if constexpr (__rank == 2) + return (_M_strides[1] >= _M_strides[0] * _M_extents.extent(0)) + || (_M_strides[0] >= _M_strides[1] * _M_extents.extent(1)); + else + { + // This is necessary, but not sufficient condition for uniquness. + // It requires computation in range of call of operator(), so check + // if first, also in non-debug mode. + if (required_span_size() < __mdspan::__size(_M_extents)) + return false; + + // Checking if pertmuation of strides exists is O(rank^2) so enabled + // only in debug mode. +#ifdef _GLIBCXX_DEBUG + _Strides __extents_arr, __strides_arr; + for (size_t __i = 0; __i < __rank; ++__i) + { + __strides_arr[__i] = _M_strides[__i]; + __extents_arr[__i] = _M_extents.extent(__i); + } + span __strides = __strides_arr; + span __extents = __extents_arr; + + auto __popmin = [](span& __vals) + { + index_type& __front = __vals.front(); + index_type* __min = &__front; + __vals = __vals.subspan(1); + for (index_type& __v : __vals) + if (__v < *__min) + __min = &__v; + + std::swap(__front, *__min); + return __front; + }; + + // We use eager selection-sort based algorithm to permute the __strides. + index_type __prev = __popmin(__strides); + while (!__strides.empty()) + { + const index_type __next = __popmin(__strides); + + // Find biggest extents that could map to this stride. + index_type* __max = nullptr; + for (index_type& __ext : __extents) + if (__next >= __prev * __ext) + if (!__max || __ext > *__max) + __max = &__ext; + + // None of the extents passes check, non-unique layout. + if (!__max) + return false; + + std::swap(__extents.front(), *__max); + __extents = __extents.subspan(1); + __prev = __next; + } +#endif + return true; + } + } + #if __glibcxx_submdspan template requires (extents_type::rank() == sizeof...(_Slices)) @@ -2047,8 +2128,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } #endif - using _Strides = typename __array_traits::_Type; [[no_unique_address]] extents_type _M_extents; [[no_unique_address]] _Strides _M_strides; }; diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/stride_neg.cc b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/stride_neg.cc index 153560bc82f..96d3c63717a 100644 --- a/libstdc++-v3/testsuite/23_containers/mdspan/layouts/stride_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/mdspan/layouts/stride_neg.cc @@ -27,5 +27,47 @@ test_stride_negative() } static_assert(test_stride_negative()); // { dg-error "expansion of" } +template + constexpr bool + test_is_unique(const std::array& extents, const std::array& strides) + { + auto exts = std::dextents(extents); + auto m = std::layout_stride::mapping(exts, strides); // { dg-error "expansion of" } + (void) m; + return true; + } + +static_assert(test_is_unique<0>({}, {})); +static_assert(test_is_unique<1>({0}, {0})); // empty special case +static_assert(test_is_unique<1>({1}, {0})); // { dg-error "expansion of" } + +static_assert(test_is_unique<2>({0, 1}, {0, 0})); // empty special case +static_assert(test_is_unique<2>({1, 5}, {1, 1})); +static_assert(test_is_unique<2>({3, 4}, {3, 10})); +static_assert(test_is_unique<2>({3, 4}, {10, 3})); +static_assert(test_is_unique<2>({3, 4}, {2, 3})); // { dg-error "expansion of" } +static_assert(test_is_unique<2>({3, 4}, {1, 2})); // { dg-error "expansion of" } + +static_assert(test_is_unique<3>({0, 1, 2}, {0, 0, 0})); // empty special case +static_assert(test_is_unique<3>({1, 1, 5}, {1, 1, 1})); +static_assert(test_is_unique<3>({3, 4, 5}, {2, 11, 35})); +static_assert(test_is_unique<3>({3, 4, 5}, {35, 2, 11})); +static_assert(test_is_unique<3>({3, 4, 5}, {1, 3, 11})); // { dg-error "expansion of" } +static_assert(test_is_unique<3>({3, 4, 5}, {1, 2, 12})); // { dg-error "expansion of" } +// Passes required_span_size check, detected only in debug mode +static_assert(test_is_unique<3>({3, 4, 5}, {1, 2, 25})); // { dg-error "expansion of" "" { target debug_mode } } +static_assert(test_is_unique<3>({3, 4, 5}, {1, 5, 12})); // { dg-error "expansion of" "" { target debug_mode } } + +static_assert(test_is_unique<4>({0, 1, 2, 3}, {0, 0, 0, 0})); // empty special case +static_assert(test_is_unique<4>({1, 1, 1, 5}, {1, 1, 1, 1})); +static_assert(test_is_unique<4>({3, 4, 5, 6}, {3, 16, 65, 200})); +static_assert(test_is_unique<4>({3, 4, 5, 6}, {200, 65, 3, 16})); +static_assert(test_is_unique<4>({3, 4, 5, 6}, {1, 3, 12, 50})); // { dg-error "expansion of" } +static_assert(test_is_unique<4>({3, 4, 5, 6}, {1, 3, 11, 60})); // { dg-error "expansion of" } +static_assert(test_is_unique<4>({3, 4, 5, 6}, {1, 2, 12, 60})); // { dg-error "expansion of" } +// Passes required_span_size check, detected only in debug mode +static_assert(test_is_unique<4>({3, 4, 5, 6}, {1, 2, 12, 100})); // { dg-error "expansion of" "" { target debug_mode } } +static_assert(test_is_unique<4>({3, 4, 5, 6}, {1, 5, 12, 60})); // { dg-error "expansion of" "" { target debug_mode } } + // { dg-prune-output "non-constant condition for static assertion" } // { dg-prune-output "__glibcxx_assert_fail()" }