From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 6A7E6386EC45 for ; Mon, 21 Sep 2020 18:45:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6A7E6386EC45 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-394-XNqs1YtZOYy744G5Bj-mzw-1; Mon, 21 Sep 2020 14:45:37 -0400 X-MC-Unique: XNqs1YtZOYy744G5Bj-mzw-1 Received: by mail-qv1-f69.google.com with SMTP id h9so9666339qvr.3 for ; Mon, 21 Sep 2020 11:45:37 -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=I63TlmsyEGUaXipvXEilrV02CA1MYi0cZ5G8/RJBBForSphYGgezlbXPTEsByTifpe +rRliL2YGdvuh39hDOU/vm7e8YKqefO6QkMDwy5qQZooOss87DAqCIAfhhGYkVw4FD9o ugCKeDYARamGhv8qxnE55vfMtH30jioJWVFeN68E0KZCi8Piq4OxTs7AhJGsLMt6Lck0 f32ZXvRDA9Fa5NCIsnypNZ+q0AHwm/i+y3xX1pEHA6KYkRAwh9ij3lHH2AGd4/LowqMv NXI2+8EGbbuW9lOP9+4D+hpu8WEhB7xb8WQbHxcjaXR0Hy50h87ZCxyBoZvdIs4C6eft TxNw== X-Gm-Message-State: AOAM533pABs+1gDgYSr8tGsdUEr5OTyUvWkiSBK8WtAi8erHnhJNXv6v IdF0nY8jLB214RIEv+SC9OIIlK6ZcWkPrwCqwQkUSAk2QMgKUo5kryX+4edNMP5m5snUOWdkKN3 AAaMf3j8693VDeGc= X-Received: by 2002:aed:3c4c:: with SMTP id u12mr898581qte.312.1600713936903; 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) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka 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 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit 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, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, 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: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Sep 2020 18:45:43 -0000 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 } -- 2.28.0.497.g54e85e7af1