From patchwork Mon Sep 21 18:45:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1368572 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=N+RHzBxH; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BwD0W1tD4z9sTr for ; Tue, 22 Sep 2020 04:45:47 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7BDDE386F01D; Mon, 21 Sep 2020 18:45:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7BDDE386F01D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600713944; bh=a4g8FM51AiVYksibsRoW4aap95Kc3PbIW6YxjecUUDg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=N+RHzBxHJrDLxIkeIWUjZblN2KZ2J5Q4v32IGYKCHzz7XH+0miypp427kQok0f+25 upDdjI5ZZYWPO24DLfv6jMa/Cq7XBZNDIk7ApB2ljhawR/Av2dBpeMZDhS//jQG/Jh oRmhbKeUrVSDZdMR5I+8iEnAmQTN+JnObL50M5X8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by sourceware.org (Postfix) with ESMTP id 503F33851C16 for ; Mon, 21 Sep 2020 18:45:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 503F33851C16 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-337-7gesUW0rP1y7qvIYjatFnw-1; Mon, 21 Sep 2020 14:45:38 -0400 X-MC-Unique: 7gesUW0rP1y7qvIYjatFnw-1 Received: by mail-qv1-f69.google.com with SMTP id bo17so9747251qvb.2 for ; Mon, 21 Sep 2020 11:45:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=a4g8FM51AiVYksibsRoW4aap95Kc3PbIW6YxjecUUDg=; b=KDaKPPhTphKdCK4wUjmhMpmvRU8kRBXNo4DFWGdrLLIL6km5DjSlddRvn781lwe6qN PO8Goaz9wxY+6hjyn9rCl1Ifl1Z4M+RbGTdxn3meIsWMsmtGFT1kv7w38eVZwEslUzWB TjnumVqBKuPEN7m9mJuaO7vDwNkmTGD8ULJE62vqTtZOTJWrA+lCsMvyfDTFVbNjKls7 VMZ3xKbEkabSmQcpW3HRhRoadnALbRfa93CKGT5h8NUT56q4xgqVFMbhU9u7eUqNtvwm hPoeihVJru3mGbKz8xNThiyB9UyNnjE6q8TkZMgrhY1tILJiiOb5sGw3k0DHj+ryrWT0 N84w== X-Gm-Message-State: AOAM5339wsWDV4LbuItxCCMubbChnfU1n2fLCtH/tcGtQz8ulYMjuhyu uWNFeNCsIf2hrJVIXZPGqblfr1MgDybf3rdNrtE0BJFYtUd7PANfrXQ5u2MxYd1W6bhVsnD/24e T+nnub5vpUOhVYNVHwA== X-Received: by 2002:aed:3c4c:: with SMTP id u12mr898580qte.312.1600713936900; Mon, 21 Sep 2020 11:45:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy839f2ZRAVE62BiL4jrX9AoQ6kcRAi9WfIsZr85+HcnH+/GsGR2NDbQEnpw/BwLQPFy3UPAA== X-Received: by 2002:aed:3c4c:: with SMTP id u12mr898568qte.312.1600713936599; Mon, 21 Sep 2020 11:45:36 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id l92sm10498520qte.38.2020.09.21.11.45.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 11:45:35 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Remove overzealous static_asserts from std::span Date: Mon, 21 Sep 2020 14:45:33 -0400 Message-Id: <20200921184533.3909335-1-ppalka@redhat.com> X-Mailer: git-send-email 2.28.0.497.g54e85e7af1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-16.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Cc: libstdc++@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" For a span with empty static extent, we currently model the preconditions of front(), back(), and operator[] as if they were mandates, by using a static_assert to verify that extent != 0. This causes us to incorrectly reject valid programs that instantiate these member functions but never call them. libstdc++-v3/ChangeLog: * include/std/span (span::front): Remove static_assert. (span::back): Likewise. (span::operator[]): Likewise. * testsuite/23_containers/span/back_neg.cc: Remove. * testsuite/23_containers/span/front_neg.cc: Remove. * testsuite/23_containers/span/index_op_neg.cc: Remove. --- libstdc++-v3/include/std/span | 3 -- .../testsuite/23_containers/span/back_neg.cc | 29 ------------------- .../testsuite/23_containers/span/front_neg.cc | 29 ------------------- .../23_containers/span/index_op_neg.cc | 29 ------------------- 4 files changed, 90 deletions(-) delete mode 100644 libstdc++-v3/testsuite/23_containers/span/back_neg.cc delete mode 100644 libstdc++-v3/testsuite/23_containers/span/front_neg.cc delete mode 100644 libstdc++-v3/testsuite/23_containers/span/index_op_neg.cc diff --git a/libstdc++-v3/include/std/span b/libstdc++-v3/include/std/span index f658adb04cf..1cdc0589ddb 100644 --- a/libstdc++-v3/include/std/span +++ b/libstdc++-v3/include/std/span @@ -264,7 +264,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr reference front() const noexcept { - static_assert(extent != 0); __glibcxx_assert(!empty()); return *this->_M_ptr; } @@ -272,7 +271,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr reference back() const noexcept { - static_assert(extent != 0); __glibcxx_assert(!empty()); return *(this->_M_ptr + (size() - 1)); } @@ -280,7 +278,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr reference operator[](size_type __idx) const noexcept { - static_assert(extent != 0); __glibcxx_assert(__idx < size()); return *(this->_M_ptr + __idx); } diff --git a/libstdc++-v3/testsuite/23_containers/span/back_neg.cc b/libstdc++-v3/testsuite/23_containers/span/back_neg.cc deleted file mode 100644 index c451ed10df8..00000000000 --- a/libstdc++-v3/testsuite/23_containers/span/back_neg.cc +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2019-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 } } - -#include - -void -test01() -{ - std::span s; - s.back(); // { dg-error "here" } -} -// { dg-error "static assertion failed" "" { target *-*-* } 0 } diff --git a/libstdc++-v3/testsuite/23_containers/span/front_neg.cc b/libstdc++-v3/testsuite/23_containers/span/front_neg.cc deleted file mode 100644 index 38f87aa2cd5..00000000000 --- a/libstdc++-v3/testsuite/23_containers/span/front_neg.cc +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2019-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 } } - -#include - -void -test01() -{ - std::span s; - s.front(); // { dg-error "here" } -} -// { dg-error "static assertion failed" "" { target *-*-* } 0 } diff --git a/libstdc++-v3/testsuite/23_containers/span/index_op_neg.cc b/libstdc++-v3/testsuite/23_containers/span/index_op_neg.cc deleted file mode 100644 index 1e8b2d8724e..00000000000 --- a/libstdc++-v3/testsuite/23_containers/span/index_op_neg.cc +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2019-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 } } - -#include - -void -test01() -{ - std::span s; - s[99]; // { dg-error "here" } -} -// { dg-error "static assertion failed" "" { target *-*-* } 0 }