From patchwork Tue Sep 6 20:21:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1044 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp817700wrt; Tue, 6 Sep 2022 13:21:55 -0700 (PDT) X-Google-Smtp-Source: AA6agR7VY+vpA0eA2ZyUZD1B77TEs9tBmAsIUXbRMmjLm/Oj+WcRa4RFn+Qq+ZphucbOTvyxdSXS X-Received: by 2002:a17:906:5d04:b0:722:f46c:b891 with SMTP id g4-20020a1709065d0400b00722f46cb891mr151910ejt.4.1662495715469; Tue, 06 Sep 2022 13:21:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662495715; cv=none; d=google.com; s=arc-20160816; b=sI3XGRpxp7QjqxHWKNm1rBweJLDnFEi4sWTEHZxSf1epwEGgwYt5Tyl8KNAdczdoXW YEYv3Tchsn86uf5rxexlTcM+AP1EIYrNpUAXfbjjtk9IsyTXAZUI9MFv4H8IlZDPlXrt 1OYyCsbMvbGSD8sKwlQncaUPloqnGU5XMglDj70QqQXxrdwWYPLEBLb3Tc9OkLyijKxI uDfVqlvf3YQeMjlJrMALzGW0Ggf/K7jT7Y3V8OvhycvUK74yetW+V0wQWz39QnoC0q1M bp8XDKalkyTa0zEbhsqckSqmd/3OfUtw3/5x/4tH7K88ew9+b76IxoFgkRtgbSYSu1uR 8Kyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=5hS2IV8tJAdg6bgKPOUbglxE0jqJko3jzS4AyqiqzdE=; b=yyJrwIrOxLyOHhG/BsCvdg+ajGItJ62eZr75sHW5A3oUyQmd8IWwkWC3u2kp15hoCB XH3ajkTMAQZOmjtm8wtfrxSKEmT/UTEZorBJ1qWjo93VyLLkZWk2BBSSOlmuL2x/hItD PmWKdEpXuddIXcwzRE0wCUzjLCC6IGysuHPAHOMAmu6BtNbKuxoHKVLSh1OB74t3wq+X RAS38ZDxSGEPJ+8y0VhhRM9S2zd8Cka/vH6v9xOgU+ZuoROOJ2NsGuKH4LtJv9vPnn01 f6UmoAKIqw4rlorP+zOkwpT7w3BLRbGMJYoXm8r/yA++4YvImwCbTERHWPb30ndoXCcI 3vZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xunhna1I; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ds15-20020a0564021ccf00b0043d84f9413dsi787338edb.604.2022.09.06.13.21.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 13:21:55 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xunhna1I; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 677173853553 for ; Tue, 6 Sep 2022 20:21:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 677173853553 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662495714; bh=5hS2IV8tJAdg6bgKPOUbglxE0jqJko3jzS4AyqiqzdE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=xunhna1IH9EHR61dyjIcDNOLDWSpHmT2HpRwS16b60CXKDJ7KRpdHB1blzVkfBFJf rRAgAlnj8k0X+w317x5w6rUWlKS8Zq8soB2d1ZvbJ+x2jgPRtDVJfxBD1T6Jef7jdO QXIcwDOjyijxJr8RuMc1GlxfLA92hARU8ulyqHZk= 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 CC20D3858297 for ; Tue, 6 Sep 2022 20:21:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CC20D3858297 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-563-5S9d7QI4PeaupZ1SitNH7Q-1; Tue, 06 Sep 2022 16:21:08 -0400 X-MC-Unique: 5S9d7QI4PeaupZ1SitNH7Q-1 Received: by mail-qv1-f69.google.com with SMTP id ok32-20020a0562143ca000b004a10b5f97e6so5514433qvb.12 for ; Tue, 06 Sep 2022 13:21:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date; bh=5hS2IV8tJAdg6bgKPOUbglxE0jqJko3jzS4AyqiqzdE=; b=YGCeYE923dVTfOwqVeJ+fwsN8MP1a6LKTUTiYLyw7n/CB6VY1Fw6wzDibga1YPN2Xg G8bjIqXGpDmF93apuiQZS6qv3Ec1uoaz8XayYVh2GUZeS12kLQw1/YsRgHxsklPB5EPp LTeROJ9B+mDXxOiWsk+WR1Z6sxdDcbLyXGT2ChIcVjSiq1CJo3kqkfdpH+Ak76ARjgvR z5usUGaSo+rUkVOYLnc9dA3/QCtkpW/orVas7UAb5AX/4rBC9TVjFa0ZRZCz+Wf7QYBn JzwcGQMDkpm4AY+Ob7MTf+3eOEgqAuHEYG06cW2UFG87otwuoCv+wpvJSeF5k1p57dU4 j4Yg== X-Gm-Message-State: ACgBeo1jbTtY+dERZ6z5J+OWr+Nn6fA5dlM7V0EJC4ZpV3J7uuDUn+3Y 7sDUpc+PTpAYwtgz+u88Y7W4nto4VCmyxcBIE8zowm4q9J3gkgxElKH5ixu3Y1VOAH7xxRGlys/ IQ7J6noETqB5oxP8+NXf7O7JToPNXXXwIHTCbaq9hqvYTYnNt3V0pBSVijAmK0ReYtw== X-Received: by 2002:ac8:5f53:0:b0:343:a8d0:c81b with SMTP id y19-20020ac85f53000000b00343a8d0c81bmr261861qta.489.1662495668208; Tue, 06 Sep 2022 13:21:08 -0700 (PDT) X-Received: by 2002:ac8:5f53:0:b0:343:a8d0:c81b with SMTP id y19-20020ac85f53000000b00343a8d0c81bmr261831qta.489.1662495667847; Tue, 06 Sep 2022 13:21:07 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id a9-20020ac844a9000000b0034305a91aaesm9931969qto.83.2022.09.06.13.21.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 13:21:07 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: C++23 operator[] allows default arguments Date: Tue, 6 Sep 2022 16:21:05 -0400 Message-Id: <20220906202105.1398675-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.2 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1743253107693444345?= X-GMAIL-MSGID: =?utf-8?q?1743253107693444345?= This usage was intended to be allowed by P2128, but it didn't make it into the final wording. Fixed by CWG 2507. Tested x86_64-pc-linux-gnu, applying to trunk. DR2507 gcc/cp/ChangeLog: * decl.cc (grok_op_properties): Return sooner for C++23 op[]. gcc/testsuite/ChangeLog: * g++.dg/cpp23/subscript8.C: New test. --- gcc/cp/decl.cc | 11 +++++------ gcc/testsuite/g++.dg/cpp23/subscript8.C | 7 +++++++ 2 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp23/subscript8.C base-commit: 0a4a2667dc115ca73b552fcabf8570620dfbe55f diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index b72b2a8456b..6d20765f40c 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -15331,6 +15331,11 @@ grok_op_properties (tree decl, bool complain) "operator ()". */ return true; + /* C++23 allows an arbitrary number of parameters and default arguments for + operator[], and none of the other checks below apply. */ + if (operator_code == ARRAY_REF && cxx_dialect >= cxx23) + return true; + if (operator_code == COND_EXPR) { /* 13.4.0.3 */ @@ -15344,10 +15349,6 @@ grok_op_properties (tree decl, bool complain) { if (!arg) { - /* Variadic. */ - if (operator_code == ARRAY_REF && cxx_dialect >= cxx23) - break; - error_at (loc, "%qD must not have variable number of arguments", decl); return false; @@ -15408,8 +15409,6 @@ grok_op_properties (tree decl, bool complain) case OVL_OP_FLAG_BINARY: if (arity != 2) { - if (operator_code == ARRAY_REF && cxx_dialect >= cxx23) - break; error_at (loc, methodp ? G_("%qD must have exactly one argument") diff --git a/gcc/testsuite/g++.dg/cpp23/subscript8.C b/gcc/testsuite/g++.dg/cpp23/subscript8.C new file mode 100644 index 00000000000..fe000359d41 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/subscript8.C @@ -0,0 +1,7 @@ +// DR2507: Allow default arguments +// { dg-additional-options {-std=c++23} } + +struct A +{ + void operator[](int, int = 42); +};