Message ID | 20220527003343.537118-1-polacek@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95AD0382D50F for <patchwork@sourceware.org>; Fri, 27 May 2022 00:34:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95AD0382D50F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1653611659; bh=hY4HAVtm7+TzxD2yTW7DLVboOGJB4D/MbQFbh0Un5Cc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=A6V2JuYp5+Na+PXfNMw9xj4OnrXVyZcf4O742HOVWYOhiPyic0ic4OGtUQspbvIYA GWkYeV6dAKbQbefU3/MmVzXBFB90KEUOgkbOseZdhmDJuVO4lKMDuGn1JIEn8p2Xm+ h0OMw/FbBMI8LOfh61ED5dRin2z0NzEZGwL5lpYg= 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 5712B382DB39 for <gcc-patches@gcc.gnu.org>; Fri, 27 May 2022 00:33:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5712B382DB39 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-397-oyjNWA2yOheongSJ_L9ORA-1; Thu, 26 May 2022 20:33:48 -0400 X-MC-Unique: oyjNWA2yOheongSJ_L9ORA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4FB11801E6B for <gcc-patches@gcc.gnu.org>; Fri, 27 May 2022 00:33:48 +0000 (UTC) Received: from pdp-11.hsd1.ma.comcast.net (unknown [10.22.9.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B2B140D282F; Fri, 27 May 2022 00:33:48 +0000 (UTC) To: Jason Merrill <jason@redhat.com>, GCC Patches <gcc-patches@gcc.gnu.org> Subject: [PATCH] c++: Add !TYPE_P assert to type_dependent_expression_p [PR99080] Date: Thu, 26 May 2022 20:33:43 -0400 Message-Id: <20220527003343.537118-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=-12.7 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_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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Marek Polacek via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Marek Polacek <polacek@redhat.com> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
c++: Add !TYPE_P assert to type_dependent_expression_p [PR99080]
|
|
Commit Message
Marek Polacek
May 27, 2022, 12:33 a.m. UTC
As discussed here: <https://gcc.gnu.org/pipermail/gcc-patches/2021-February/564629.html>, type_dependent_expression_p should not be called with a type argument. I promised I'd add an assert so here it is. One place needed adjusting, the comment explains why. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? PR c++/99080 gcc/cp/ChangeLog: * pt.cc (type_dependent_expression_p): Assert !TYPE_P. * semantics.cc (finish_id_expression_1): Don't call type_dependent_expression_p for a type. --- gcc/cp/pt.cc | 2 ++ gcc/cp/semantics.cc | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) base-commit: 367740bf6d3a6627798b3955e5d85efc7549ef50
Comments
On 5/26/22 20:33, Marek Polacek wrote: > As discussed here: > <https://gcc.gnu.org/pipermail/gcc-patches/2021-February/564629.html>, > type_dependent_expression_p should not be called with a type argument. > > I promised I'd add an assert so here it is. One place needed adjusting, > the comment explains why. > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > PR c++/99080 > > gcc/cp/ChangeLog: > > * pt.cc (type_dependent_expression_p): Assert !TYPE_P. > * semantics.cc (finish_id_expression_1): Don't call > type_dependent_expression_p for a type. > --- > gcc/cp/pt.cc | 2 ++ > gcc/cp/semantics.cc | 4 +++- > 2 files changed, 5 insertions(+), 1 deletion(-) > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 24bbe2f4060..89156cb88b4 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -27727,6 +27727,8 @@ type_dependent_expression_p (tree expression) > if (expression == NULL_TREE || expression == error_mark_node) > return false; > > + gcc_checking_assert (!TYPE_P (expression)); > + > STRIP_ANY_LOCATION_WRAPPER (expression); > > /* An unresolved name is always dependent. */ > diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc > index cd7a2818feb..7f8502f49b0 100644 > --- a/gcc/cp/semantics.cc > +++ b/gcc/cp/semantics.cc > @@ -4141,7 +4141,9 @@ finish_id_expression_1 (tree id_expression, > } > else > { > - bool dependent_p = type_dependent_expression_p (decl); > + /* DECL could be e.g. UNBOUND_CLASS_TEMPLATE which is a type which > + t_d_e_p doesn't accept. */ > + bool dependent_p = !TYPE_P (decl) && type_dependent_expression_p (decl); Maybe instead we could handle UNBOUND_CLASS_TEMPLATE at a higher level in the function, like with an 'else if' before this 'else'? > /* If the declaration was explicitly qualified indicate > that. The semantics of `A::f(3)' are different than > > base-commit: 367740bf6d3a6627798b3955e5d85efc7549ef50
On Fri, May 27, 2022 at 11:52:12AM -0400, Jason Merrill wrote: > On 5/26/22 20:33, Marek Polacek wrote: > > As discussed here: > > <https://gcc.gnu.org/pipermail/gcc-patches/2021-February/564629.html>, > > type_dependent_expression_p should not be called with a type argument. > > > > I promised I'd add an assert so here it is. One place needed adjusting, > > the comment explains why. > > > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > > > PR c++/99080 > > > > gcc/cp/ChangeLog: > > > > * pt.cc (type_dependent_expression_p): Assert !TYPE_P. > > * semantics.cc (finish_id_expression_1): Don't call > > type_dependent_expression_p for a type. > > --- > > gcc/cp/pt.cc | 2 ++ > > gcc/cp/semantics.cc | 4 +++- > > 2 files changed, 5 insertions(+), 1 deletion(-) > > > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > > index 24bbe2f4060..89156cb88b4 100644 > > --- a/gcc/cp/pt.cc > > +++ b/gcc/cp/pt.cc > > @@ -27727,6 +27727,8 @@ type_dependent_expression_p (tree expression) > > if (expression == NULL_TREE || expression == error_mark_node) > > return false; > > + gcc_checking_assert (!TYPE_P (expression)); > > + > > STRIP_ANY_LOCATION_WRAPPER (expression); > > /* An unresolved name is always dependent. */ > > diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc > > index cd7a2818feb..7f8502f49b0 100644 > > --- a/gcc/cp/semantics.cc > > +++ b/gcc/cp/semantics.cc > > @@ -4141,7 +4141,9 @@ finish_id_expression_1 (tree id_expression, > > } > > else > > { > > - bool dependent_p = type_dependent_expression_p (decl); > > + /* DECL could be e.g. UNBOUND_CLASS_TEMPLATE which is a type which > > + t_d_e_p doesn't accept. */ > > + bool dependent_p = !TYPE_P (decl) && type_dependent_expression_p (decl); > > Maybe instead we could handle UNBOUND_CLASS_TEMPLATE at a higher level in > the function, like with an 'else if' before this 'else'? Maybe, but I think I'd have to duplicate (parts of) this block: 4227 else if (scope) 4228 { 4229 if (TREE_CODE (decl) == SCOPE_REF) 4230 { 4231 gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0))); 4232 decl = TREE_OPERAND (decl, 1); 4233 } 4234 4235 decl = (adjust_result_of_qualified_name_lookup 4236 (decl, scope, current_nonlambda_class_type())); 4237 4238 cp_warn_deprecated_use_scopes (scope); 4239 4240 if (TYPE_P (scope)) 4241 decl = finish_qualified_id_expr (scope, 4242 decl, 4243 done, 4244 address_p, 4245 template_p, 4246 template_arg_p, 4247 tf_warning_or_error); 4248 else 4249 decl = convert_from_reference (decl); 4250 } Would that be acceptable? Can't do else if (TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE) { gcc_checking_assert (scope); *idk = CP_ID_KIND_QUALIFIED; goto do_scope; } because that will complain about skipping the initialization of dependent_p. Here's a patch with the partial duplication, which passes dg.exp: -- >8 -- As discussed here: <https://gcc.gnu.org/pipermail/gcc-patches/2021-February/564629.html>, type_dependent_expression_p should not be called with a type argument. I promised I'd add an assert so here it is. One place needed adjusting. PR c++/99080 gcc/cp/ChangeLog: * pt.cc (type_dependent_expression_p): Assert !TYPE_P. * semantics.cc (finish_id_expression_1): Handle UNBOUND_CLASS_TEMPLATE specifically. --- gcc/cp/pt.cc | 2 ++ gcc/cp/semantics.cc | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 24bbe2f4060..89156cb88b4 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -27727,6 +27727,8 @@ type_dependent_expression_p (tree expression) if (expression == NULL_TREE || expression == error_mark_node) return false; + gcc_checking_assert (!TYPE_P (expression)); + STRIP_ANY_LOCATION_WRAPPER (expression); /* An unresolved name is always dependent. */ diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index cdc91a38e25..f62b0a4a736 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -4139,6 +4139,17 @@ finish_id_expression_1 (tree id_expression, } return r; } + else if (TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE) + { + gcc_checking_assert (scope); + *idk = CP_ID_KIND_QUALIFIED; + decl = (adjust_result_of_qualified_name_lookup + (decl, scope, current_nonlambda_class_type())); + cp_warn_deprecated_use_scopes (scope); + decl = finish_qualified_id_expr (scope, decl, done, address_p, + template_p, template_arg_p, + tf_warning_or_error); + } else { bool dependent_p = type_dependent_expression_p (decl); base-commit: d822f4bbd714c6595f70cc68888dcebecfb6662d
On 5/27/22 12:43, Marek Polacek wrote: > On Fri, May 27, 2022 at 11:52:12AM -0400, Jason Merrill wrote: >> On 5/26/22 20:33, Marek Polacek wrote: >>> As discussed here: >>> <https://gcc.gnu.org/pipermail/gcc-patches/2021-February/564629.html>, >>> type_dependent_expression_p should not be called with a type argument. >>> >>> I promised I'd add an assert so here it is. One place needed adjusting, >>> the comment explains why. >>> >>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? >>> >>> PR c++/99080 >>> >>> gcc/cp/ChangeLog: >>> >>> * pt.cc (type_dependent_expression_p): Assert !TYPE_P. >>> * semantics.cc (finish_id_expression_1): Don't call >>> type_dependent_expression_p for a type. >>> --- >>> gcc/cp/pt.cc | 2 ++ >>> gcc/cp/semantics.cc | 4 +++- >>> 2 files changed, 5 insertions(+), 1 deletion(-) >>> >>> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc >>> index 24bbe2f4060..89156cb88b4 100644 >>> --- a/gcc/cp/pt.cc >>> +++ b/gcc/cp/pt.cc >>> @@ -27727,6 +27727,8 @@ type_dependent_expression_p (tree expression) >>> if (expression == NULL_TREE || expression == error_mark_node) >>> return false; >>> + gcc_checking_assert (!TYPE_P (expression)); >>> + >>> STRIP_ANY_LOCATION_WRAPPER (expression); >>> /* An unresolved name is always dependent. */ >>> diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc >>> index cd7a2818feb..7f8502f49b0 100644 >>> --- a/gcc/cp/semantics.cc >>> +++ b/gcc/cp/semantics.cc >>> @@ -4141,7 +4141,9 @@ finish_id_expression_1 (tree id_expression, >>> } >>> else >>> { >>> - bool dependent_p = type_dependent_expression_p (decl); >>> + /* DECL could be e.g. UNBOUND_CLASS_TEMPLATE which is a type which >>> + t_d_e_p doesn't accept. */ >>> + bool dependent_p = !TYPE_P (decl) && type_dependent_expression_p (decl); >> >> Maybe instead we could handle UNBOUND_CLASS_TEMPLATE at a higher level in >> the function, like with an 'else if' before this 'else'? > > Maybe, but I think I'd have to duplicate (parts of) this block: > 4227 else if (scope) > 4228 { > 4229 if (TREE_CODE (decl) == SCOPE_REF) > 4230 { > 4231 gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0))); > 4232 decl = TREE_OPERAND (decl, 1); > 4233 } > 4234 > 4235 decl = (adjust_result_of_qualified_name_lookup > 4236 (decl, scope, current_nonlambda_class_type())); > 4237 > 4238 cp_warn_deprecated_use_scopes (scope); > 4239 > 4240 if (TYPE_P (scope)) > 4241 decl = finish_qualified_id_expr (scope, > 4242 decl, > 4243 done, > 4244 address_p, > 4245 template_p, > 4246 template_arg_p, > 4247 tf_warning_or_error); > 4248 else > 4249 decl = convert_from_reference (decl); > 4250 } > > Would that be acceptable? Can't do > > else if (TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE) > { > gcc_checking_assert (scope); > *idk = CP_ID_KIND_QUALIFIED; > goto do_scope; > } > because that will complain about skipping the initialization of dependent_p. > > Here's a patch with the partial duplication, which passes dg.exp: > > -- >8 -- > As discussed here: > <https://gcc.gnu.org/pipermail/gcc-patches/2021-February/564629.html>, > type_dependent_expression_p should not be called with a type argument. > > I promised I'd add an assert so here it is. One place needed adjusting. > > PR c++/99080 > > gcc/cp/ChangeLog: > > * pt.cc (type_dependent_expression_p): Assert !TYPE_P. > * semantics.cc (finish_id_expression_1): Handle UNBOUND_CLASS_TEMPLATE > specifically. > --- > gcc/cp/pt.cc | 2 ++ > gcc/cp/semantics.cc | 11 +++++++++++ > 2 files changed, 13 insertions(+) > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 24bbe2f4060..89156cb88b4 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -27727,6 +27727,8 @@ type_dependent_expression_p (tree expression) > if (expression == NULL_TREE || expression == error_mark_node) > return false; > > + gcc_checking_assert (!TYPE_P (expression)); > + > STRIP_ANY_LOCATION_WRAPPER (expression); > > /* An unresolved name is always dependent. */ > diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc > index cdc91a38e25..f62b0a4a736 100644 > --- a/gcc/cp/semantics.cc > +++ b/gcc/cp/semantics.cc > @@ -4139,6 +4139,17 @@ finish_id_expression_1 (tree id_expression, > } > return r; > } > + else if (TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE) > + { > + gcc_checking_assert (scope); > + *idk = CP_ID_KIND_QUALIFIED; > + decl = (adjust_result_of_qualified_name_lookup > + (decl, scope, current_nonlambda_class_type())); This call should have no effect, it only affects BASELINKs. OK without this statement. > + cp_warn_deprecated_use_scopes (scope); > + decl = finish_qualified_id_expr (scope, decl, done, address_p, > + template_p, template_arg_p, > + tf_warning_or_error); > + } > else > { > bool dependent_p = type_dependent_expression_p (decl); > > base-commit: d822f4bbd714c6595f70cc68888dcebecfb6662d
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 24bbe2f4060..89156cb88b4 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -27727,6 +27727,8 @@ type_dependent_expression_p (tree expression) if (expression == NULL_TREE || expression == error_mark_node) return false; + gcc_checking_assert (!TYPE_P (expression)); + STRIP_ANY_LOCATION_WRAPPER (expression); /* An unresolved name is always dependent. */ diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index cd7a2818feb..7f8502f49b0 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -4141,7 +4141,9 @@ finish_id_expression_1 (tree id_expression, } else { - bool dependent_p = type_dependent_expression_p (decl); + /* DECL could be e.g. UNBOUND_CLASS_TEMPLATE which is a type which + t_d_e_p doesn't accept. */ + bool dependent_p = !TYPE_P (decl) && type_dependent_expression_p (decl); /* If the declaration was explicitly qualified indicate that. The semantics of `A::f(3)' are different than