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 [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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662495670; 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=5hS2IV8tJAdg6bgKPOUbglxE0jqJko3jzS4AyqiqzdE=; b=FU5Eqd9cmakrdScUTmBUxMqE6dpMhoJ45z0z8+j6x/pxeh8s+8aJPeTV03elxgBuFP8TE3 vn7ZJCWTZ0/rknNuOFX63fNaW750FN1ASogsFbe//V3nq7HZvaelO85rQTFkA3aeh5dgNg ATYKMI7NrXiHInKQrT1BxQZ6ra7vnLc= 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-Google-Smtp-Source: AA6agR6/MajdXnbasYkjLVmMqIDp4Lq+SwEz8wVyv/fRwO4qwAfcrpW8sIgYyZwkxObyTvz/fkXM3A== 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) From: Jason Merrill 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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 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); +}; base-commit: 0a4a2667dc115ca73b552fcabf8570620dfbe55f -- 2.31.1