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 D7F7F3858D20 for ; Fri, 2 Dec 2022 20:01:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D7F7F3858D20 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=1670011318; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9+r9qOjljoBDX+lWsxf/70o+jZWWTpnvpwJbE0Mr+D8=; b=WroPWRpBtYFRTtI+0DUkgmQe5HvlB+3uUK19FR6oedidHKH217a0m0xIrTNOC+DzT6BE7B Y+g6hg5V4b8tzVbnHHzYM0re8zzZN5k0YAcTABXYlmS7j/qGFgBICe/12sZI8HDTvPizet 4jiJXscT3pew9DnP1q6nK7AeVGIQ4lQ= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-14-ednbZkb0NwOKGmgLMDSKVw-1; Fri, 02 Dec 2022 15:01:57 -0500 X-MC-Unique: ednbZkb0NwOKGmgLMDSKVw-1 Received: by mail-qv1-f72.google.com with SMTP id on28-20020a056214449c00b004bbf12d7976so18943962qvb.18 for ; Fri, 02 Dec 2022 12:01:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc: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=9+r9qOjljoBDX+lWsxf/70o+jZWWTpnvpwJbE0Mr+D8=; b=sYvxS+jDimQNCleN1rMX8AhYDo+8ada59+8ZQUgekEjVttDZk+fEcrKJqP7dniUny/ uNmwYofEL7NnqrYT/N0Fi7ZRUhBHlgplkoeNTvemtDdDJCFFy8JKEqdvUlmDWKQShnJd 8Bh/WIC8cPuvnB3AO29bJQ94bqT0+lAeq7WOsgRLqwdKfhgGjeu1lKC5a8OItcQta6rT q0LNQmRpM1wRMUELbkCEkIFCLDbvhJNRdFTQuFkKWi+xhw46jWAs21H8ZRIuWfCK+SgG TGByxNeaBaIRY8BzX9IN/N6mXwKrzVyE0qyZHmfDPmWnX9IcgeFSax6dL6hq77IKXE1v WkbQ== X-Gm-Message-State: ANoB5pmbvHO5PpXu6SZsaaeMeYytq79mc3glfT/B8r+ZqFMEcY/gunz1 +BpNiFC2keMiy5Xf874avRz146VEA2gFGDaMd3QQ8e0c1mSoTnZPPZPKu5qGOg340tqNo9AXruF 02Vn09/VZR5aKJHZHxQ== X-Received: by 2002:a05:6214:3246:b0:4c7:3114:b20e with SMTP id mt6-20020a056214324600b004c73114b20emr6978597qvb.48.1670011316732; Fri, 02 Dec 2022 12:01:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf56FVZHgzeB/zdJHCBKhG+ErH1Tq25J/a0byyuZT2FNd3bzadGBZqPLBDy28OWoG8XngIpngQ== X-Received: by 2002:a05:6214:3246:b0:4c7:3114:b20e with SMTP id mt6-20020a056214324600b004c73114b20emr6978555qvb.48.1670011316268; Fri, 02 Dec 2022 12:01:56 -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 c4-20020a05620a268400b006ec62032d3dsm6192927qkp.30.2022.12.02.12.01.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 02 Dec 2022 12:01:55 -0800 (PST) Message-ID: Date: Fri, 2 Dec 2022 15:01:54 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH v3] c++: P2448 - Relaxing some constexpr restrictions [PR106649] To: Marek Polacek Cc: GCC Patches References: <20221109205305.96262-1-polacek@redhat.com> <5cfabd39-8afe-931c-7872-1b4360d2e5b5@redhat.com> <8ce934d2-4775-2d27-6154-1b677dedc5a6@redhat.com> <44e97804-e4d8-f1b4-8456-8577f2e5a8ab@redhat.com> From: Jason Merrill In-Reply-To: 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: 8bit X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00,BODY_8BITS,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,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 12/2/22 14:48, Marek Polacek wrote: > On Fri, Nov 18, 2022 at 09:26:26PM -0500, Jason Merrill wrote: >> On 11/16/22 15:27, Jason Merrill wrote: >>> On 11/16/22 11:06, Marek Polacek wrote: >>>> On Wed, Nov 16, 2022 at 08:41:53AM -0500, Jason Merrill wrote: >>>>> On 11/15/22 19:30, Marek Polacek wrote: >>>>>> @@ -996,19 +1040,26 @@ register_constexpr_fundef (const >>>>>> constexpr_fundef &value) >>>>>>      **slot = value; >>>>>>    } >>>>>> -/* FUN is a non-constexpr function called in a context that requires a >>>>>> -   constant expression.  If it comes from a constexpr >>>>>> template, explain why >>>>>> -   the instantiation isn't constexpr.  */ >>>>>> +/* FUN is a non-constexpr (or, with -Wno-invalid-constexpr, >>>>>> a constexpr >>>>>> +   function called in a context that requires a constant expression). >>>>>> +   If it comes from a constexpr template, explain why the >>>>>> instantiation >>>>>> +   isn't constexpr.  */ >>>>> >>>>> The "if it comes from a constexpr template" wording has needed >>>>> an update for >>>>> a while now. >>>> >>>> Probably ever since r178519.  I've added "Otherwise, explain why the >>>> function >>>> cannot be used in a constexpr context."  Is that acceptable? >>>>>> --- /dev/null >>>>>> +++ b/gcc/testsuite/g++.dg/cpp23/constexpr-nonlit15.C >>>>>> @@ -0,0 +1,43 @@ >>>>>> +// PR c++/106649 >>>>>> +// P2448 - Relaxing some constexpr restrictions >>>>>> +// { dg-do compile { target c++23 } } >>>>>> +// { dg-options "-Winvalid-constexpr" } >>>>>> +// A copy/move assignment operator for a class X that is defaulted and >>>>>> +// not defined as deleted is implicitly defined when it is odr-used, >>>>>> +// when it is needed for constant evaluation, or when it is explicitly >>>>>> +// defaulted after its first declaration. >>>>>> +// The implicitly-defined copy/move assignment operator is constexpr. >>>>>> + >>>>>> +struct S { >>>>>> +  constexpr S() {} >>>>>> +  S& operator=(const S&) = default; // #1 >>>>>> +  S& operator=(S&&) = default; // #2 >>>>>> +}; >>>>>> + >>>>>> +struct U { >>>>>> +  constexpr U& operator=(const U&) = default; >>>>>> +  constexpr U& operator=(U&&) = default; >>>>>> +}; >>>>>> + >>>>>> +/* FIXME: If we only declare #1 and #2, and default them here: >>>>>> + >>>>>> +   S& S::operator=(const S&) = default; >>>>>> +   S& S::operator=(S&&) = default; >>>>>> + >>>>>> +then they aren't constexpr.  This sounds like a bug: >>>>>> +.  */ >>>>> >>>>> As I commented on the PR, I don't think this is actually a bug, so let's >>>>> omit this FIXME. >>>> >>>> I'm glad I didn't really attempt to "fix" it (the inform message is >>>> flawed >>>> and should be improved).  Thanks for taking a look. >>>> >>>> Here's a version with the two comments updated. >>>> >>>> Ok? >>> >>> OK. >> >> Since this patch I'm seeing these failures: >> >> FAIL: g++.dg/cpp0x/constexpr-ex1.C -std=c++23 -fimplicit-constexpr at line >> 91 (test for errors, line 89) >> FAIL: g++.dg/cpp23/constexpr-nonlit10.C -std=gnu++23 -fimplicit-constexpr >> (test for warnings, line 14) >> FAIL: g++.dg/cpp23/constexpr-nonlit10.C -std=gnu++23 -fimplicit-constexpr >> (test for warnings, line 20) >> FAIL: g++.dg/cpp23/constexpr-nonlit11.C -std=gnu++23 -fimplicit-constexpr >> (test for warnings, line 28) >> FAIL: g++.dg/cpp23/constexpr-nonlit11.C -std=gnu++23 -fimplicit-constexpr >> (test for warnings, line 31) >> FAIL: g++.dg/cpp2a/spaceship-eq3.C -std=c++23 -fimplicit-constexpr (test >> for excess errors) > > Ah, sorry. The following patch fixes those fails. > > Ok? OK, thanks. > -- >8 -- > Some of the new tests were failing with -fimplicit-constexpr. This > patch adjusts the expected diagnostic. Tested with > > GXX_TESTSUITE_STDS=98,11,14,17,20,23 make check-c++ RUNTESTFLAGS="--target_board=unix\{,-fimplicit-constexpr\} dg.exp=spaceship-eq3.C" > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp0x/constexpr-ex1.C: Adjust dg-error. > * g++.dg/cpp23/constexpr-nonlit10.C: Adjust dg-warning. > * g++.dg/cpp23/constexpr-nonlit11.C: Likewise. > * g++.dg/cpp2a/spaceship-eq3.C: Add dg-error. > --- > gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C | 6 +++--- > gcc/testsuite/g++.dg/cpp23/constexpr-nonlit10.C | 4 ++-- > gcc/testsuite/g++.dg/cpp23/constexpr-nonlit11.C | 4 ++-- > gcc/testsuite/g++.dg/cpp2a/spaceship-eq3.C | 1 + > 4 files changed, 8 insertions(+), 7 deletions(-) > > diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C > index 48281a47784..383d38a42d4 100644 > --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C > +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C > @@ -87,8 +87,8 @@ struct resource { > } > }; > constexpr resource f(resource d) > -{ return d; } // { dg-error "non-.constexpr." "" { target { { ! implicit_constexpr } && c++20_down } } } > -// { dg-error "non-.constexpr." "" { target c++23 } .-2 } > -constexpr resource d = f(9); // { dg-message ".constexpr." "" { target { ! implicit_constexpr } } } > +{ return d; } // { dg-error "non-.constexpr." "" { target { { { ! implicit_constexpr } && c++20_down } || c++11_only } } } > +// { dg-error "non-.constexpr." "" { target { c++23 && { ! implicit_constexpr } } } .-2 } > +constexpr resource d = f(9); // { dg-message ".constexpr." "" { target { { ! implicit_constexpr } || c++11_only } } } > > // 4.4 floating-point constant expressions > diff --git a/gcc/testsuite/g++.dg/cpp23/constexpr-nonlit10.C b/gcc/testsuite/g++.dg/cpp23/constexpr-nonlit10.C > index 48706f7b66e..31d4b873bbf 100644 > --- a/gcc/testsuite/g++.dg/cpp23/constexpr-nonlit10.C > +++ b/gcc/testsuite/g++.dg/cpp23/constexpr-nonlit10.C > @@ -11,13 +11,13 @@ struct NonLiteral { > // C++23: It is possible to write a constexpr function for which no > // invocation satisfies the requirements of a core constant expression. > constexpr NonLiteral > -fn0 (int) // { dg-warning "invalid return type" } > +fn0 (int) // { dg-warning "invalid return type" "" { target { ! implicit_constexpr } } } > { > return NonLiteral{}; > } > > constexpr int > -fn1 (NonLiteral) // { dg-warning "invalid type" } > +fn1 (NonLiteral) // { dg-warning "invalid type" "" { target { ! implicit_constexpr } } } > { > return 42; > } > diff --git a/gcc/testsuite/g++.dg/cpp23/constexpr-nonlit11.C b/gcc/testsuite/g++.dg/cpp23/constexpr-nonlit11.C > index a7114bc66cb..e08809f873c 100644 > --- a/gcc/testsuite/g++.dg/cpp23/constexpr-nonlit11.C > +++ b/gcc/testsuite/g++.dg/cpp23/constexpr-nonlit11.C > @@ -25,10 +25,10 @@ struct X { > struct S { > X x; > // Calls a non-constexpr constructor X::X(int). > - constexpr S(int i) : x(i) { } // { dg-warning "call to" } > + constexpr S(int i) : x(i) { } // { dg-warning "call to" "" { target { ! implicit_constexpr } } } > S(int, int) { } > // Target constructor isn't constexpr. > - constexpr S() : S(42, 42) { } // { dg-warning "call to" } > + constexpr S() : S(42, 42) { } // { dg-warning "call to" "" { target { ! implicit_constexpr } } } > }; > > namespace N1 { > diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-eq3.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-eq3.C > index 69eaa7b9b20..246839f1f95 100644 > --- a/gcc/testsuite/g++.dg/cpp2a/spaceship-eq3.C > +++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-eq3.C > @@ -9,6 +9,7 @@ struct D > A i; > bool operator==(const D& x) const = default; // { dg-error "A::operator==" "" { target c++20_down } } > bool operator!=(const D& z) const = default; // { dg-error "D::operator==" "" { target c++20_down } } > +// { dg-error "called" "" { target { c++23 && implicit_constexpr } } .-1 } > }; > > constexpr D d{A()}; > > base-commit: d19aa6af6634b1e97f38431ad091f3b3f12baf2f