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.133.124]) by sourceware.org (Postfix) with ESMTPS id 3341B3858439 for ; Wed, 1 Mar 2023 20:34:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3341B3858439 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=1677702865; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=r7zliMZQCPck/6XJ7oV2DuuuyQYyXOHkYRZbXMEM+WY=; b=cQGt+h/dG/gFV4IIOULLDfQ5uIFVfZkyjBFWEG8tOFMt6dOZc0YI+Zi86w3EdcLBm3nORI 6n0ZJexaecb4blZPbT10ldPCmVLQDwYfu9eI/2r6qYSrNcjtRY5+Lp6bix63m1svY4PliG nDQbRYcVZFBOYDvarEMZj4sR+hQZH7U= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-180-G9vc9T8sOqugs6I5IuKJXQ-1; Wed, 01 Mar 2023 15:34:24 -0500 X-MC-Unique: G9vc9T8sOqugs6I5IuKJXQ-1 Received: by mail-qt1-f197.google.com with SMTP id g20-20020ac870d4000000b003b9c1013018so7203683qtp.18 for ; Wed, 01 Mar 2023 12:34:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r7zliMZQCPck/6XJ7oV2DuuuyQYyXOHkYRZbXMEM+WY=; b=T27MUnLIqJtlGUDDuX8OZmWpDe77jiUrp1AS9ZRyahEm6CsPOtYVtN3fdb3snf4Lxo yQGFZJzSw9EbWcqwIVp65OpjhvvovixC8Sh2QfDmksXiLsITXI9d7bA9dJEtTWljW5sz WOgTbEbpWtpyMSrSjBpTgBlL4q2IY17ezKlETkGGTIFFouOP5UY5aJEf0Wk70MpQSs7G tiryMpDXWekYU4hjtFFioKkHesDWeCb5p42lHYkR2b/79dD2Xg8C1ib3TNg/zaN3wSGe 8D92j00BxEnVf/aORCEfioZjgjbxTgo8Yk1BXUs0MQSoSkf8SltCL7+Z2IEHLEZMKg36 Zxsg== X-Gm-Message-State: AO0yUKV12E+ME8eJv2jdZKHUDPcQSShtnpJEQCuFu1cFATNQYyP4HzhV m0V8/X6fp7rAZy2kE2fcKCVZdd7lzNVECIMB0eYeyyGkPy27aVULjow2Ksu0oW3EireTACPzbUA qBWR7XRNdEOoRkQkmJg== X-Received: by 2002:ac8:5dd1:0:b0:3b8:6ae9:b10d with SMTP id e17-20020ac85dd1000000b003b86ae9b10dmr13293621qtx.2.1677702863839; Wed, 01 Mar 2023 12:34:23 -0800 (PST) X-Google-Smtp-Source: AK7set9FSoAF8tKtr1GzuTRKXVzFPZxqsk7ghEzlVpVZeb99dzIpKwnHuvOzaZ1C7S5h57toOOOL0A== X-Received: by 2002:ac8:5dd1:0:b0:3b8:6ae9:b10d with SMTP id e17-20020ac85dd1000000b003b86ae9b10dmr13293591qtx.2.1677702863559; Wed, 01 Mar 2023 12:34:23 -0800 (PST) Received: from redhat.com (2603-7000-9500-34a5-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:34a5::1db4]) by smtp.gmail.com with ESMTPSA id t8-20020ac85888000000b003bb8c60cdf1sm9219826qta.78.2023.03.01.12.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Mar 2023 12:34:23 -0800 (PST) Date: Wed, 1 Mar 2023 15:34:21 -0500 From: Marek Polacek To: Jason Merrill , GCC Patches Subject: Re: [PATCH] c++: can't eval PTRMEM_CST in incomplete class [PR107574] Message-ID: References: <20230203002825.398939-1-polacek@redhat.com> MIME-Version: 1.0 In-Reply-To: <20230203002825.398939-1-polacek@redhat.com> User-Agent: Mutt/2.2.9 (2022-11-12) 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=-12.7 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_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: Ping. On Thu, Feb 02, 2023 at 07:28:25PM -0500, Marek Polacek via Gcc-patches 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; > + } > return cp_fold_convert (type, op); > } > > diff --git a/gcc/testsuite/g++.dg/cpp0x/ptrmem-cst1.C b/gcc/testsuite/g++.dg/cpp0x/ptrmem-cst1.C > new file mode 100644 > index 00000000000..0d6a6b6445d > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp0x/ptrmem-cst1.C > @@ -0,0 +1,11 @@ > +// PR c++/107574 > +// { dg-do compile { target c++11 } } > + > +struct A { int i; }; > +struct B:A { int j; }; > +struct C:B { > + int k; > + static_assert((int B::*) &C::k, ""); // { dg-error "non-constant|still incomplete" } > +}; > + > +static_assert((int B::*) &C::k, ""); > > base-commit: 07c87fce63541846ca2951e22dac04fcaa66475f > -- > 2.39.1 > Marek