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 6BB5F3858D3C for ; Wed, 30 Mar 2022 13:04:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6BB5F3858D3C Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-428-OgK2dIcqPo6QpX9tlj1uwQ-1; Wed, 30 Mar 2022 09:04:00 -0400 X-MC-Unique: OgK2dIcqPo6QpX9tlj1uwQ-1 Received: by mail-qv1-f69.google.com with SMTP id p65-20020a0c90c7000000b004412a2a1a6cso16005200qvp.3 for ; Wed, 30 Mar 2022 06:03:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=xuC3OHElVgwEFg6fECW3PhW3+RZxS1Ttmvmhh6ZFBwg=; b=PUXnd1xKZo6S3FgBrAb0Z33+qIv+TKTVlXLiZ0sQsspIr4eQ7HvGtIrxyOQ8Zg5D44 RHhVtqsMH0STQGtWgy401Xr8mw9cNqW5yeNCmIVVvocUlTNpLkuE/GqRnTW+eHeFskZB w63jIJbR1cY27tXsTkN1iV2F5GM+47YOQoHBtoZUHJw593hRsJ2QSMKGwgRBUBQ3ICEr uK5R9QCbol5ipjo2EzVb/hYYqIwE8FXS499bHW2A+JUq55NxunorjDegVvFJpRQONDBv I0rSsSz/cVvIk4zT+tAT5Wu4+duNBQ+UJw/pmsClz944kShzTXufcMSajnxFyb6J/j0L qLXg== X-Gm-Message-State: AOAM532v9hBBwqk4WhDzj2M7FchpA8Zmb6Xj6/QD6Sg2y8CgZ7GZdTWR FrrqcEZwhMa8QuPUtr29ToTkFkj8mht3QrVuXHvpLGoehnLCCzKFjLCcHFzkl4BOQyU5McYE4zj w+mQi//qxm4KhXWY+Fw== X-Received: by 2002:a05:6214:c83:b0:441:51c7:9dc9 with SMTP id r3-20020a0562140c8300b0044151c79dc9mr30782492qvr.83.1648645437797; Wed, 30 Mar 2022 06:03:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdKiO0gn162UWaTMQlj/gRf0XQ2KIt/UNxJxUgHnq6KKrGSDCoc6TeN5S3K7dRNH8UvrFEmw== X-Received: by 2002:a05:6214:c83:b0:441:51c7:9dc9 with SMTP id r3-20020a0562140c8300b0044151c79dc9mr30782460qvr.83.1648645437408; Wed, 30 Mar 2022 06:03:57 -0700 (PDT) Received: from [192.168.1.149] (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 c11-20020a05620a134b00b006809a92a94fsm10662573qkl.79.2022.03.30.06.03.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Mar 2022 06:03:56 -0700 (PDT) Message-ID: Date: Wed, 30 Mar 2022 09:03:55 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH] c++: ICE with failed __is_constructible constraint [PR100474] To: Patrick Palka Cc: gcc-patches@gcc.gnu.org References: <20220329192230.255163-1-ppalka@redhat.com> <63ae6234-0e06-3b9b-f938-afb92cc5dbf6@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=-13.4 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_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Mar 2022 13:04:04 -0000 On 3/30/22 08:56, Patrick Palka wrote: > On Tue, 29 Mar 2022, Jason Merrill wrote: > >> On 3/29/22 15:22, Patrick Palka wrote: >>> Here we're crashing when diagnosing a failed __is_constructible constraint >>> because diagnose_atomic_constraint don't know how to diagnose a trait >>> that diagnose_trait_expr doesn't specifically handle. This patch fixes >>> this by falling through to the default case in this situation. >>> >>> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for >>> trunk and perhaps 11? >> >> Hmm, it seems reasonable, but I think it would be better to actually handle >> all the traits. Removing the default, I get >> >>> constraint.cc:3585:10: warning: enumeration value ‘CPTK_BASES’ not handled >>> in switch [-Wswitch] >>> constraint.cc:3585:10: warning: enumeration value ‘CPTK_DIRECT_BASES’ not >>> handled in switch [-Wswitch] >>> constraint.cc:3585:10: warning: enumeration value ‘CPTK_UNDERLYING_TYPE’ not >>> handled in switch [-Wswitch] >> >> These we don't need to handle. >> >>> constraint.cc:3585:10: warning: enumeration value >>> ‘CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS’ not handled in switch \ >>> constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_AGGREGATE’ not >>> handled in switch [-Wswitch] >>> constraint.cc:3585:10: warning: enumeration value >>> ‘CPTK_IS_TRIVIALLY_ASSIGNABLE’ not handled in switch [-Wswit\ >>> constraint.cc:3585:10: warning: enumeration value >>> ‘CPTK_IS_TRIVIALLY_CONSTRUCTIBLE’ not handled in switch [-Ws\ >>> constraint.cc:3585:10: warning: enumeration value >>> ‘CPTK_IS_TRIVIALLY_COPYABLE’ not handled in switch [-Wswitch\ >>> constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_ASSIGNABLE’ not >>> handled in switch [-Wswitch] >>> constraint.cc:3585:10: warning: enumeration value ‘CPTK_IS_CONSTRUCTIBLE’ >>> not handled in switch [-Wswitch] >>> constraint.cc:3585:10: warning: enumeration value >>> ‘CPTK_IS_NOTHROW_ASSIGNABLE’ not handled in switch [-Wswitch\ >>> constraint.cc:3585:10: warning: enumeration value >>> ‘CPTK_IS_NOTHROW_CONSTRUCTIBLE’ not handled in switch [-Wswi\ >> >> These we should. >> >> I think we should leave off the default so that when we add more traits we get >> a warning that we need to handle them here. > > Sounds good, like so? Let's leave a comment about why there's no 'default'. OK with that change. > -- >8 -- > > Subject: [PATCH] c++: ICE with failed __is_constructible constraint [PR100474] > > Here we're crashing when diagnosing a failed __is_constructible constraint > because diagnose_trait_expr doesn't recognize this trait (along with a > bunch of other traits). Fix this by adding handling for all remaining > traits and removing the default case so that when we add a new trait we > get a warning that diagnose_trait_expr needs to handle it. > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk and perhaps 11? > > PR c++/100474 > > gcc/cp/ChangeLog: > > * constraint.cc (diagnose_trait_expr): Handle all remaining > traits appropriately. Remove default case. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/concepts-traits3.C: New test. > --- > gcc/cp/constraint.cc | 41 +++++++++++- > gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C | 66 +++++++++++++++++++ > 2 files changed, 106 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C > > diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc > index c5a991b9e71..b970ac9772d 100644 > --- a/gcc/cp/constraint.cc > +++ b/gcc/cp/constraint.cc > @@ -3654,7 +3654,46 @@ diagnose_trait_expr (tree expr, tree args) > case CPTK_IS_UNION: > inform (loc, " %qT is not a union", t1); > break; > - default: > + case CPTK_IS_AGGREGATE: > + inform (loc, " %qT is not an aggregate", t1); > + break; > + case CPTK_IS_TRIVIALLY_COPYABLE: > + inform (loc, " %qT is not trivially copyable", t1); > + break; > + case CPTK_IS_ASSIGNABLE: > + inform (loc, " %qT is not assignable from %qT", t1, t2); > + break; > + case CPTK_IS_TRIVIALLY_ASSIGNABLE: > + inform (loc, " %qT is not trivially assignable from %qT", t1, t2); > + break; > + case CPTK_IS_NOTHROW_ASSIGNABLE: > + inform (loc, " %qT is not % assignable from %qT", t1, t2); > + break; > + case CPTK_IS_CONSTRUCTIBLE: > + if (!t2) > + inform (loc, " %qT is not default constructible", t1); > + else > + inform (loc, " %qT is not constructible from %qE", t1, t2); > + break; > + case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: > + if (!t2) > + inform (loc, " %qT is not trivially default constructible", t1); > + else > + inform (loc, " %qT is not trivially constructible from %qE", t1, t2); > + break; > + case CPTK_IS_NOTHROW_CONSTRUCTIBLE: > + if (!t2) > + inform (loc, " %qT is not % default constructible", t1); > + else > + inform (loc, " %qT is not % constructible from %qE", t1, t2); > + break; > + case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS: > + inform (loc, " %qT does not have unique object representations", t1); > + break; > + case CPTK_BASES: > + case CPTK_DIRECT_BASES: > + case CPTK_UNDERLYING_TYPE: > + /* We shouldn't see these non-expression traits. */ > gcc_unreachable (); > } > } > diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C b/gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C > new file mode 100644 > index 00000000000..f20608b6918 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C > @@ -0,0 +1,66 @@ > +// PR c++/100474 > +// { dg-do compile { target c++20 } } > + > +struct S { S() = delete; S(const S&); }; > + > +template > +concept Aggregate = __is_aggregate(T); > +// { dg-message "'S' is not an aggregate" "" { target *-*-* } .-1 } > + > +template > +concept TriviallyCopyable = __is_trivially_copyable(T); > +// { dg-message "'S' is not trivially copyable" "" { target *-*-* } .-1 } > + > +template > +concept Assignable = __is_assignable(T, U); > +// { dg-message "'S' is not assignable from 'int'" "" { target *-*-* } .-1 } > + > +template > +concept TriviallyAssignable = __is_trivially_assignable(T, U); > +// { dg-message "'S' is not trivially assignable from 'int'" "" { target *-*-* } .-1 } > + > +template > +concept NothrowAssignable = __is_nothrow_assignable(T, U); > +// { dg-message "'S' is not 'nothrow' assignable from 'int'" "" { target *-*-* } .-1 } > + > +template > +concept Constructible = __is_constructible(T, Args...); > +// { dg-message "'S' is not default constructible" "" { target *-*-* } .-1 } > +// { dg-message "'S' is not constructible from 'int'" "" { target *-*-* } .-2 } > +// { dg-message "'S' is not constructible from 'int, char'" "" { target *-*-* } .-3 } > + > +template > +concept TriviallyConstructible = __is_trivially_constructible(T, Args...); > +// { dg-message "'S' is not trivially default constructible" "" { target *-*-* } .-1 } > +// { dg-message "'S' is not trivially constructible from 'int'" "" { target *-*-* } .-2 } > +// { dg-message "'S' is not trivially constructible from 'int, char'" "" { target *-*-* } .-3 } > + > +template > +concept NothrowConstructible = __is_nothrow_constructible(T, Args...); > +// { dg-message "'S' is not 'nothrow' default constructible" "" { target *-*-* } .-1 } > +// { dg-message "'S' is not 'nothrow' constructible from 'int'" "" { target *-*-* } .-2 } > +// { dg-message "'S' is not 'nothrow' constructible from 'int, char'" "" { target *-*-* } .-3 } > + > +template > +concept UniqueObjReps = __has_unique_object_representations(T); > +// { dg-message "'S' does not have unique object representations" "" { target *-*-* } .-1 } > + > +static_assert(Aggregate); // { dg-error "assert" } > +static_assert(TriviallyCopyable); // { dg-error "assert" } > +static_assert(Assignable); // { dg-error "assert" } > +static_assert(TriviallyAssignable); // { dg-error "assert" } > +static_assert(NothrowAssignable); // { dg-error "assert" } > + > +static_assert(Constructible); // { dg-error "assert" } > +static_assert(Constructible); // { dg-error "assert" } > +static_assert(Constructible); // { dg-error "assert" } > + > +static_assert(TriviallyConstructible); // { dg-error "assert" } > +static_assert(TriviallyConstructible); // { dg-error "assert" } > +static_assert(TriviallyConstructible); // { dg-error "assert" } > + > +static_assert(NothrowConstructible); // { dg-error "assert" } > +static_assert(NothrowConstructible); // { dg-error "assert" } > +static_assert(NothrowConstructible); // { dg-error "assert" } > + > +static_assert(UniqueObjReps); // { dg-error "assert" }