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 AAFCC3858D33 for ; Wed, 1 Mar 2023 21:24:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AAFCC3858D33 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=1677705864; 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: in-reply-to:in-reply-to:references:references; bh=Ea6BzskhvYD13vM9GVKYZxT81/0mC+jArG4WRIG7mDY=; b=gwwXnz8QOvQvcAEdhsYIXGE5EHYJXbiXwNRZLsL6/d02Ej2JaJGZQj7itnBYXcnLBME8hy OeBCFeZNwSRCPej2VJVrTsC2PzCbaLGjSAdzS4Jk9IIrrXJQvybP2MvH45XEKylFQjdCN/ 84kZz/QrE9+tasSlzF+zqT7QTGECFqQ= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-475-n5lKauegN4-W5q02EufrQA-1; Wed, 01 Mar 2023 16:24:23 -0500 X-MC-Unique: n5lKauegN4-W5q02EufrQA-1 Received: by mail-qk1-f200.google.com with SMTP id ou5-20020a05620a620500b007423e532628so8814648qkn.5 for ; Wed, 01 Mar 2023 13:24:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677705863; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ea6BzskhvYD13vM9GVKYZxT81/0mC+jArG4WRIG7mDY=; b=DqBLNfS+kkgPd+1HtRR0xB5FvzzD8nqMgOh+9zsj4ugaYLmC+8cX6n7jf/Mo6HMDRV zIyOlUgdaeXBFaXv1NxLYYtmpbzOo1TKsYZMUDIWjk/FvJzYS8C8lWkzbh3KEJdAsgLb DgdPyWg4G/eoiWLThJVIlEgZZ11bKSTVzTqNQKtc+glr6gXaho5aoNfPwbEPPAnMQ3lf uPo2DZ+ot14caTTCxrnHT9ZunPBaUwKpIFmCNvjp+BEbHQQm4cQM4JJPE//j+xkZdg4e 2PFr+4/oixnbim5XvDN6MAUhpwLXP/3d8wqtgU6o0IS50oPg8BqgUg7ds4yGfO2yk+G9 qhgQ== X-Gm-Message-State: AO0yUKWWX1vjyiJ6wt3NIjXZdgqDPN7w0vsysRYmqocc77cdCQ+3+wg0 uQTM2z34X1TygR+piA0HD64pbIdBgcxbYXoTnm7cvOfQVMybZFXQvGBhoHF4uBER6kd3thW0FKA BX+fI1TXU1p+DHIyBeQ== X-Received: by 2002:ac8:5bc4:0:b0:3b8:5f26:e81f with SMTP id b4-20020ac85bc4000000b003b85f26e81fmr14339079qtb.26.1677705862706; Wed, 01 Mar 2023 13:24:22 -0800 (PST) X-Google-Smtp-Source: AK7set/JKt1uyuQKvb6f8owQVu/y/IDAI8GOZ1Mx3CHVMUJBU9DOIupsA3L4spjc5JjM4IV+qQ+ANw== X-Received: by 2002:ac8:5bc4:0:b0:3b8:5f26:e81f with SMTP id b4-20020ac85bc4000000b003b85f26e81fmr14339043qtb.26.1677705862279; Wed, 01 Mar 2023 13:24:22 -0800 (PST) Received: from [192.168.1.108] (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 y17-20020ac85251000000b003b9bb59543fsm8933538qtn.61.2023.03.01.13.24.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 01 Mar 2023 13:24:21 -0800 (PST) Message-ID: Date: Wed, 1 Mar 2023 16:24:19 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH] c++: can't eval PTRMEM_CST in incomplete class [PR107574] To: Marek Polacek , GCC Patches References: <20230203002825.398939-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: <20230203002825.398939-1-polacek@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP 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: On 2/2/23 19:28, Marek Polacek wrote: > Here we're attempting to evaluate a PTRMEM_CST in a class that hasn't > been completed yet, but that doesn't work: > > /* We can't lower this until the class is complete. */ > if (!COMPLETE_TYPE_P (DECL_CONTEXT (member))) > return cst; > > and then this unlowered PTRMEM_CST is used as EXPR in > > tree op1 = build_nop (ptrdiff_type_node, expr); > > and we crash in a subsequent cp_fold_convert which gets type=ptrdiff_type_node, > expr=PTRMEM_CST and does > > else if (TREE_CODE (expr) == PTRMEM_CST > && same_type_p (TYPE_PTRMEM_CLASS_TYPE (type), > PTRMEM_CST_CLASS (expr))) > > where TYPE_PTRMEM_CLASS_TYPE (type) is going to crash since the type > is ptrdiff_type_node. We could just add a TYPE_PTRMEM_P check before > accessing TYPE_PTRMEM_CLASS_TYPE but I think it's nicer to explain why > we couldn't evaluate the expression. > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > PR c++/107574 > > gcc/cp/ChangeLog: > > * constexpr.cc (cxx_eval_constant_expression): Emit an error when > a PTRMEM_CST cannot be evaluated. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp0x/ptrmem-cst1.C: New test. > --- > gcc/cp/constexpr.cc | 9 +++++++++ > gcc/testsuite/g++.dg/cpp0x/ptrmem-cst1.C | 11 +++++++++++ > 2 files changed, 20 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/cpp0x/ptrmem-cst1.C > > diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc > index 5b31f9c27d1..2c03988b097 100644 > --- a/gcc/cp/constexpr.cc > +++ b/gcc/cp/constexpr.cc > @@ -7691,6 +7691,15 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, > if (!same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (op)) > && !can_convert_qual (type, op)) > op = cplus_expand_constant (op); > + if (TREE_CODE (op) == PTRMEM_CST && !TYPE_PTRMEM_P (type)) > + { > + if (!ctx->quiet) > + error_at (loc, "%qE is not a constant expression when the " > + "class %qT is still incomplete", op, > + PTRMEM_CST_CLASS (op)); > + *non_constant_p = true; > + return t; > + } Hmm, maybe handle this a few lines higher, in this existing if: > if (TREE_CODE (op) == PTRMEM_CST && !TYPE_PTRMEM_P (type)) > op = cplus_expand_constant (op); ? OK with that change.