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 B0B5C3888829 for ; Tue, 29 Mar 2022 08:05:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B0B5C3888829 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-639-LgWnSGNjP7mnQGpzdhFP0Q-1; Tue, 29 Mar 2022 04:05:23 -0400 X-MC-Unique: LgWnSGNjP7mnQGpzdhFP0Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 46D37185A7BA for ; Tue, 29 Mar 2022 08:05:23 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 02AE540CF905; Tue, 29 Mar 2022 08:05:22 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 22T85Kd12569545 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 29 Mar 2022 10:05:20 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 22T85KPN2569544; Tue, 29 Mar 2022 10:05:20 +0200 Date: Tue, 29 Mar 2022 10:05:20 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fox template-introduction tentative parsing in class bodies clear colon_corrects_to_scope_p [PR105061] Message-ID: Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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 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: Tue, 29 Mar 2022 08:05:28 -0000 Hi! The concepts support (in particular template introductions from concepts TS) broke the following testcase, valid unnamed bitfields with dependent types (or even just typedefs) were diagnosed as typos (: instead of correct ::) in template introduction during their tentative parsing. The following patch fixes that by not doing this : to :: correction when member_p is true. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and release branches (so far also bootstrapped/regtested on the above targets on 11 branch)? 2022-03-29 Jakub Jelinek PR c++/105061 * parser.cc (cp_parser_template_introduction): If member_p, temporarily clear parser->colon_corrects_to_scope_p around tentative parsing of nested name specifier. * g++.dg/concepts/pr105061.C: New test. --- gcc/cp/parser.cc.jj 2022-03-26 08:11:50.030217910 +0100 +++ gcc/cp/parser.cc 2022-03-28 17:30:41.488053848 +0200 @@ -31417,9 +31417,15 @@ cp_parser_template_introduction (cp_pars tree saved_scope = parser->scope; tree saved_object_scope = parser->object_scope; tree saved_qualifying_scope = parser->qualifying_scope; + bool saved_colon_corrects_to_scope_p = parser->colon_corrects_to_scope_p; cp_token *start_token = cp_lexer_peek_token (parser->lexer); + /* In classes don't parse valid unnamed bitfields as invalid + template introductions. */ + if (member_p) + parser->colon_corrects_to_scope_p = false; + /* Look for the optional `::' operator. */ cp_parser_global_scope_opt (parser, /*current_scope_valid_p=*/false); @@ -31440,6 +31446,7 @@ cp_parser_template_introduction (cp_pars parser->scope = saved_scope; parser->object_scope = saved_object_scope; parser->qualifying_scope = saved_qualifying_scope; + parser->colon_corrects_to_scope_p = saved_colon_corrects_to_scope_p; if (concept_name == error_mark_node || (seen_error () && !concept_definition_p (tmpl_decl))) --- gcc/testsuite/g++.dg/concepts/pr105061.C.jj 2022-03-28 17:34:02.051207207 +0200 +++ gcc/testsuite/g++.dg/concepts/pr105061.C 2022-03-28 17:33:14.502882074 +0200 @@ -0,0 +1,13 @@ +// PR c++/105061 + +template +struct A { T : V, u : U; }; +template +struct B { unsigned : V, u : U; }; +typedef unsigned uns; +template +struct C { uns : V, u : U; }; + +A a = { 13 }; +B<5, 6> b = { 26 }; +C<8, 9> c = { 42 }; Jakub