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 7BC6238582B0 for ; Mon, 20 Nov 2023 21:29:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7BC6238582B0 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7BC6238582B0 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700515782; cv=none; b=CtfkFnfmG4I7VDNyTJ6+LpPFBMqm/OkclmvXGznqDuaygDOjWEbggd51WNTXuw/jYPSDVqSXL8ruUaTmiwUpuhsWNrr5/9RZevTfawTezPYJDvYzqWjzENh9oE/UvR10RvmSd48ZQsfoJ2negvN7i3uf2vEb8CvzKLRA32MyGIU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700515782; c=relaxed/simple; bh=IkgCl4f/E7h+z+DGDuuM7Gp81W0BSi3hNXVA2+CS03E=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=hjScBBj7gfFBoMO8jJIzPGxavXfGZ/XcMdM6kIQaP9PgQJP56RawxcXz3bjmc3UIzBXV1jeM0f+rBnioStKFcJBf4JGSq2LtlXsw4kTXSTT/sIaw82/W1WzEGlz3/W+zfK93pgW/MaEYgOOAh8nwJW6PRCb00xvnAW0h3wCJYiQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700515780; 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=dBp07XubRzwTIoxyxN+R7YCKuABDCByVddvp9XlErfk=; b=fKp5zyMIH8K+KzlDe9q3QCC1ZisJ4cBk88oLynsR2QJJu8DtnmWr+JO3Qpp3z5obIY7gmc iElZQZfMiWMdaeWXwpOnJj0iw2nfbf54/RToB3uvS7QEkWi5FR5OMuT2Rp3voBUpFJLRch Iuvi+zeVUIGfSH4rYuhaD0xHiFq7K/U= Received: from mail-ua1-f70.google.com (mail-ua1-f70.google.com [209.85.222.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-60ximG08Nu21TQRODN-2Og-1; Mon, 20 Nov 2023 16:29:35 -0500 X-MC-Unique: 60ximG08Nu21TQRODN-2Og-1 Received: by mail-ua1-f70.google.com with SMTP id a1e0cc1a2514c-7c1a9d7a2c9so849768241.3 for ; Mon, 20 Nov 2023 13:29:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700515775; x=1701120575; 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=dBp07XubRzwTIoxyxN+R7YCKuABDCByVddvp9XlErfk=; b=PALz0StcM9Fv4+e3Mo3Vc1J6GmaV45dYSDOi8ZO2ps9f1qybxDNFeNhiu1KZtkQgH6 H8b3jJyzmreC59uMajCKk/iw17JoeXifUgD+GF0jOSiCZCWHAivHvDBFVk5OL2seQlM9 LShWwDzZ0B9XLbmGk8AFu/6MbJ4sUaT1doFviTSvSB+iDBY6c3QZdxfC4xj4E54EJnP6 DnhwWLGxvNuk92tsWSjTUB0MPltZkVpFcipw5qBNE3a/2317d1gRs/uGOdWFy3bZD195 TfY3W4DWrkfN7PJpB9hBpdDM+ohc2mGQjw/QEza7AvY6T3gGpirmPAQH7NgTnlO3uoX8 1Tyw== X-Gm-Message-State: AOJu0Yy7E+qMYttGeRp9kadupx6azEemYiwqpmspjr+pMUli7qCn7rzw 05EmopE3NlndOWNsslFLG5J8rrTnuTLfNaNlb29v99T/xSSzXCk8fJh9A4JGDw5K6LqoY8wyoEb 63/Uf3MnYTLiignTrfr+RtV/QWQ== X-Received: by 2002:a67:ef5d:0:b0:45d:9a4d:dc1b with SMTP id k29-20020a67ef5d000000b0045d9a4ddc1bmr3493287vsr.3.1700515774889; Mon, 20 Nov 2023 13:29:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFiS6G1quJMbyv3qNeAihhFZ2UAAhjLnN+X/49U4ZEgisH4mzC4KALfp7wBgCRAMz/yDTB72A== X-Received: by 2002:a67:ef5d:0:b0:45d:9a4d:dc1b with SMTP id k29-20020a67ef5d000000b0045d9a4ddc1bmr3493275vsr.3.1700515774607; Mon, 20 Nov 2023 13:29:34 -0800 (PST) Received: from [192.168.1.145] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id a1-20020a05620a438100b0077bd79682c4sm2973100qkp.5.2023.11.20.13.29.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Nov 2023 13:29:34 -0800 (PST) Message-ID: Date: Mon, 20 Nov 2023 16:29:33 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: P2280R4, Using unknown refs in constant expr [PR106650] To: Marek Polacek , GCC Patches References: <20231117214610.173872-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: <20231117214610.173872-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=-6.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 11/17/23 16:46, Marek Polacek wrote: > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > -- >8 -- > This patch is an attempt to implement (part of?) P2280, Using unknown > pointers and references in constant expressions. (Note that R4 seems to > only allow References to unknown/Accesses via this, but not Pointers to > unknown.) Indeed. That seems a bit arbitrary to me, but there it is. We were rejecting the testcase before because cxx_bind_parameters_in_call was trying to perform an lvalue->rvalue conversion on the reference itself; this isn't really a thing in the language, but worked to implement the reference bullet that the paper removes. Your approach to fixing that makes sense to me. We should do the same for VAR_DECL references, e.g. extern int (&r)[42]; constexpr int i = array_size (r); You also need to allow (implict or explicit) use of 'this', as in: struct A { constexpr int f() { return 42; } void g() { constexpr int i = f(); } }; > This patch works to the extent that the test case added in [expr.const] > works as expected, as well as the test in > > > Most importantly, the proposal makes this compile: > > template > constexpr auto array_size(T (&)[N]) -> size_t { > return N; > } > > void check(int const (¶m)[3]) { > constexpr auto s = array_size(param); > static_assert (s == 3); > } > > and I think it would be a pity not to have it in GCC 14. > > What still doesn't work (and I don't know if it should) is the test in $3.2: > > struct A2 { constexpr int f() { return 0; } }; > struct B2 : virtual A2 {}; > void f2(B2 &b) { constexpr int k = b.f(); } > > where we say > error: '* & b' is not a constant expression It seems like that is supposed to work, the problem is accessing the vtable to perform the conversion. I have WIP to recognize that conversion better in order to fix PR53288; this testcase can wait for that fix. Jason