From patchwork Thu Jun 27 08:45:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1953065 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bmJfiJn4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W8sgV2YShz20Xm for ; Thu, 27 Jun 2024 18:49:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 86BBC3838A2F for ; Thu, 27 Jun 2024 08:49:08 +0000 (GMT) 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.129.124]) by sourceware.org (Postfix) with ESMTPS id A90793839398 for ; Thu, 27 Jun 2024 08:48:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A90793839398 Authentication-Results: sourceware.org; dmarc=pass (p=none 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 A90793839398 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719478117; cv=none; b=Rai+4ZieFfRyKuO7nky1NE7LCbEHCArCII3h7gbAJGlgvvWEtB9zgd1JNz2XQXqJROpRm9+Z5w5zIEIO8KIVL+XYxauxUwbT8niVTmJDBJ7jJjhbkF79EwtMXWjx4EjQNlvD9pJ/duWM0GMkBuBv5e8WMCWTd3Cpqq782VqwlJ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719478117; c=relaxed/simple; bh=FYYEIVyBcUXPlkzTeskWNQjSKMN9w+RdtiLGL2y9BaI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=J4hvCxzngw18pYMan3dJFewBV3PtMnspukgyW26qlQvMRWbHuMLG7GIPYqr26vyWiJ8MGr9/RpV8HZFkmY7RZSRFWcKuIyq64NuO0OcNT4sqowfJvcqnIaocyC8MLEMqN12DmxC1sRdme297j1sdUiug3qDNvmcsLNEqC2yEf38= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719478111; 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=SNVfh9MwlIp2tGDrGsDmeokAUKzyDh+bawJ3s+UI730=; b=bmJfiJn4DrJsBLc54AYzN0oVXCIaE4wOlSh5Mb/0Jiq4bvGG04X3xdE646XfyOCFvDxapD 9r1OtOyro4lNvi9c1/vKwABw3zdh0gQSsC3S1sDWjGr4b0dzDmJYOP/DxQxSHdCH1BGSX/ AHWBpczy0wHmly4RYCvXdM/7YO0osXE= Received: from mx-prod-mc-02.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-465-1M8AObgvNCWGY9gj1yBtVQ-1; Thu, 27 Jun 2024 04:48:28 -0400 X-MC-Unique: 1M8AObgvNCWGY9gj1yBtVQ-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 66226194511A; Thu, 27 Jun 2024 08:48:26 +0000 (UTC) Received: from localhost (unknown [10.42.28.171]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A77211956054; Thu, 27 Jun 2024 08:48:25 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] libstdc++: Add debug assertions to std::vector [PR103191] Date: Thu, 27 Jun 2024 09:45:39 +0100 Message-ID: <20240627084821.95065-2-jwakely@redhat.com> In-Reply-To: <20240627084821.95065-1-jwakely@redhat.com> References: <20240627084821.95065-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 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, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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+incoming=patchwork.ozlabs.org@gcc.gnu.org The previous commit allows these to work for constexpr too, which is nice. Tested x86_64-linux. Pushed to trunk. -- >8 -- This adds debug assertions for std::vector element access. libstdc++-v3/ChangeLog: PR libstdc++/103191 * include/bits/stl_bvector.h (vector::operator[]) (vector::front, vector::back): Add debug assertions. * testsuite/23_containers/vector/bool/element_access/constexpr.cc: Remove dg-error that no longer triggers. --- libstdc++-v3/include/bits/stl_bvector.h | 30 +++++++++++++++---- .../vector/bool/element_access/constexpr.cc | 2 +- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index 52153cadf8f..8685cc64cc4 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -1084,12 +1084,18 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR reference operator[](size_type __n) - { return begin()[__n]; } + { + __glibcxx_requires_subscript(__n); + return begin()[__n]; + } _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_reference operator[](size_type __n) const - { return begin()[__n]; } + { + __glibcxx_requires_subscript(__n); + return begin()[__n]; + } protected: _GLIBCXX20_CONSTEXPR @@ -1133,22 +1139,34 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR reference front() - { return *begin(); } + { + __glibcxx_requires_nonempty(); + return *begin(); + } _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_reference front() const - { return *begin(); } + { + __glibcxx_requires_nonempty(); + return *begin(); + } _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR reference back() - { return *(end() - 1); } + { + __glibcxx_requires_nonempty(); + return *(end() - 1); + } _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR const_reference back() const - { return *(end() - 1); } + { + __glibcxx_requires_nonempty(); + return *(end() - 1); + } _GLIBCXX20_CONSTEXPR void diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/constexpr.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/constexpr.cc index bff9f7b4e0f..7c60e5db4d1 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/constexpr.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/constexpr.cc @@ -115,4 +115,4 @@ template constexpr std::true_type access_empty_front() { return {}; } -static_assert( ! access_empty_front() ); // { dg-error "ambiguous" "PR 103191" { target { ! debug_mode } } } +static_assert( ! access_empty_front() );