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 997C83888C5C for ; Thu, 31 Mar 2022 12:50:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 997C83888C5C Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-373-nqL86scFMkCl-0VWil_Mfg-1; Thu, 31 Mar 2022 08:50:26 -0400 X-MC-Unique: nqL86scFMkCl-0VWil_Mfg-1 Received: by mail-qt1-f200.google.com with SMTP id k11-20020ac8604b000000b002e1a4109edeso19953008qtm.15 for ; Thu, 31 Mar 2022 05:50:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=23yI3cRrQjCCRRkRgYSJXqmsJeaTR1rxuQfNo9EQwNM=; b=cFK7O5tkE21AuLO5Z1MoP79kJPBInPLAfpDnnfKoCmiqByuAdCmRxYtoAbgr7rVRv6 ouFTwOQ0BZ2nniXQmY8QAuaDVbmJF9q1HntUl4iPCIPgUoRAXSK8II9e+H7gq3CvIQxv m+Ge8d4qt29mAcNDJF0kUqnXzPDufJbxq217in5l7afsIqmI2aJP/4B1ROoRwUegLwVe be1By+hiov9RdBAu+xl2oBXmYVwW+KKOOkXOwH8EZxDgbyHpZ/XT/rxrTUqkZ9DOVQn5 hk4cY8sslFVlS67zutmMH0rRj1rVpWE7imuBZg8pwbEGbKA5XcWEQCffJ/kjJN3Eti7a //PQ== X-Gm-Message-State: AOAM531/sn6Kgp0tr+i1jhGbBc4Uz4EHSvrX1I3AIJJwzZ+66Pc3jKUR h5rc/KdCiG/ndXO2VFL46YyexpRJw+1nY/FgMDwV/A6EX0Vm1RI/jUqhqSqswzesg0XaYLnJkjM S0NZxazEfFbghKnfFdQ== X-Received: by 2002:a05:6214:2343:b0:43d:684c:f538 with SMTP id hu3-20020a056214234300b0043d684cf538mr3943063qvb.58.1648731025634; Thu, 31 Mar 2022 05:50:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAgNofdmV3Z0PCZ5hk2Zw7aCgvZzH3ir8Boz78HMYl72sovmiJy2Wz9tWLPFgDwCWfQeHTLg== X-Received: by 2002:a05:6214:2343:b0:43d:684c:f538 with SMTP id hu3-20020a056214234300b0043d684cf538mr3943044qvb.58.1648731025377; Thu, 31 Mar 2022 05:50:25 -0700 (PDT) Received: from [192.168.1.130] (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id x6-20020ac86b46000000b002e02be9c0easm16525887qts.69.2022.03.31.05.50.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 05:50:24 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Thu, 31 Mar 2022 08:50:24 -0400 (EDT) To: Jason Merrill cc: gcc-patches@gcc.gnu.org, Jonathan Wakely Subject: Re: [pushed] c++: parse trivial DMI immediately [PR96645] In-Reply-To: <20220331014312.2080968-1-jason@redhat.com> Message-ID: References: <20220331014312.2080968-1-jason@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.5 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, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset=ISO-8859-7 Content-Transfer-Encoding: 8BIT X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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-List-Received-Date: Thu, 31 Mar 2022 12:50:30 -0000 On Wed, 30 Mar 2022, Jason Merrill via Gcc-patches wrote: > The recent change to reject __is_constructible for nested classes with DMI > is breaking some code loudly that was previously only silently broken. > Let's allow simple cases by immediately parsing DMI that do no name lookup; > then being in complete class scope makes no difference. Not sure if this is a problem in practice but it seems the initializer processing step of cp_parser_late_parse_one_default_arg may involve name lookup even if the parse itself didn't: struct A { struct B { const A &a = {}; }; }; We used to accept this (very contrived example), but now reject with error: invalid use of incomplete type Ąconst struct A˘ > > Tested x86_64-pc-linux-gnu, applying to trunk. > > PR c++/96645 > > gcc/cp/ChangeLog: > > * parser.cc (cp_parser_early_parsing_nsdmi): New. > (cp_parser_member_declaration): Call it. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp0x/nsdmi10.C: Now OK. > * g++.dg/ext/is_constructible3.C: Likewise. > * g++.dg/ext/is_constructible7.C: Likewise. > --- > gcc/cp/parser.cc | 28 +++++++++++++++++++- > gcc/testsuite/g++.dg/cpp0x/nsdmi10.C | 4 +-- > gcc/testsuite/g++.dg/ext/is_constructible3.C | 2 +- > gcc/testsuite/g++.dg/ext/is_constructible7.C | 3 +-- > 4 files changed, 31 insertions(+), 6 deletions(-) > > diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc > index 7e1c777364e..63c8af1c722 100644 > --- a/gcc/cp/parser.cc > +++ b/gcc/cp/parser.cc > @@ -2701,6 +2701,8 @@ static tree cp_parser_late_parse_one_default_arg > (cp_parser *, tree, tree, tree); > static void cp_parser_late_parsing_nsdmi > (cp_parser *, tree); > +static bool cp_parser_early_parsing_nsdmi > + (cp_parser *, tree); > static void cp_parser_late_parsing_default_args > (cp_parser *, tree); > static tree cp_parser_sizeof_operand > @@ -27478,7 +27480,8 @@ cp_parser_member_declaration (cp_parser* parser) > if (DECL_DECLARES_FUNCTION_P (decl)) > cp_parser_save_default_args (parser, STRIP_TEMPLATE (decl)); > else if (TREE_CODE (decl) == FIELD_DECL > - && DECL_INITIAL (decl)) > + && DECL_INITIAL (decl) > + && !cp_parser_early_parsing_nsdmi (parser, decl)) > /* Add DECL to the queue of NSDMI to be parsed later. */ > vec_safe_push (unparsed_nsdmis, decl); > } > @@ -32292,6 +32295,29 @@ cp_parser_late_parsing_nsdmi (cp_parser *parser, tree field) > DECL_INITIAL (field) = def; > } > > +/* If the DEFERRED_PARSE for FIELD is safe to parse immediately, do so. > + Returns true if deferred parsing is no longer needed. */ > + > +static bool > +cp_parser_early_parsing_nsdmi (cp_parser *parser, tree field) > +{ > + tree init = DECL_INITIAL (field); > + if (TREE_CODE (init) != DEFERRED_PARSE) > + return true; > + > + cp_token_cache *tokens = DEFPARSE_TOKENS (init); > + for (cp_token *p = tokens->first; p != tokens->last; ++p) > + if (p->type == CPP_NAME > + || p->keyword == RID_THIS > + || p->keyword == RID_OPERATOR) > + /* There's a name to look up or 'this', give up. */ > + return false; > + > + /* It's trivial, parse now. */ > + cp_parser_late_parsing_nsdmi (parser, field); > + return true; > +} > + > /* FN is a FUNCTION_DECL which may contains a parameter with an > unparsed DEFERRED_PARSE. Parse the default args now. This function > assumes that the current scope is the scope in which the default > diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi10.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi10.C > index d8588b7f29e..a965f7bc333 100644 > --- a/gcc/testsuite/g++.dg/cpp0x/nsdmi10.C > +++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi10.C > @@ -6,7 +6,7 @@ struct A1 { > int y1 = 1; > }; > > - A1(const B1& opts = B1()) {} // { dg-error "default member initializer" } > + A1(const B1& opts = B1()) {} > }; > > struct A2 { > @@ -14,5 +14,5 @@ struct A2 { > int x2, y2 = 1; > }; > > - A2(const B2& opts = B2()) {} // { dg-error "default member initializer" } > + A2(const B2& opts = B2()) {} > }; > diff --git a/gcc/testsuite/g++.dg/ext/is_constructible3.C b/gcc/testsuite/g++.dg/ext/is_constructible3.C > index 305751d28e2..c7c58746cd0 100644 > --- a/gcc/testsuite/g++.dg/ext/is_constructible3.C > +++ b/gcc/testsuite/g++.dg/ext/is_constructible3.C > @@ -8,7 +8,7 @@ struct A { > B() = default; > }; > > - static constexpr bool v = __is_constructible (B); // { dg-error "member initializer" } > + static constexpr bool v = __is_constructible (B); > > }; > > diff --git a/gcc/testsuite/g++.dg/ext/is_constructible7.C b/gcc/testsuite/g++.dg/ext/is_constructible7.C > index 76a63bba5d0..013a1df03c6 100644 > --- a/gcc/testsuite/g++.dg/ext/is_constructible7.C > +++ b/gcc/testsuite/g++.dg/ext/is_constructible7.C > @@ -12,7 +12,7 @@ using true_type = bool_constant; > > template > struct is_default_constructible > - : bool_constant<__is_constructible(T)> // { dg-error "default member init" } > + : bool_constant<__is_constructible(T)> > { }; > > void testVarStruct() > @@ -22,7 +22,6 @@ void testVarStruct() > int number = 5; // compiles, if remove initialization > }; > > - // { dg-prune-output "could not convert" } > is_default_constructible::type t = true_type{}; > }; > } > > base-commit: 150ab50f7449cf5b496bbe6e5c60cb1adb2e2d6c > -- > 2.27.0 > >