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 2A1BD3858D3C for ; Wed, 30 Mar 2022 12:56:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2A1BD3858D3C Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-663-kaqDfK6TPwWhH7Jwh4BgHg-1; Wed, 30 Mar 2022 08:56:47 -0400 X-MC-Unique: kaqDfK6TPwWhH7Jwh4BgHg-1 Received: by mail-qk1-f197.google.com with SMTP id l68-20020a378947000000b0067df0c430d8so12433510qkd.13 for ; Wed, 30 Mar 2022 05:56:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=RdkDz2x4N/pitlNzaDfvCtPOEXuMYltDRyEmtjD7QKA=; b=KzNYnH8MuYFOtD7H7Atnbv1I0PP0K6ER7HK2yBaxv9CkRxp9MA7AL0eCi3eFEXEeRI eC+QIu2ltOsQ356K5ML3MUjiQJNDCf41klPlUYDTepJYhC0wenPhcKkh0h8SS9NOZGjJ 0xlFs91fX1T9vzaYGxDrUcTgz29KfV/sjPDZUQvJM+b3b+mKk7B9eCtjO7I/XWqCt5wR wUiESx3vXFKRvvdJ9tV5DYO8g61DFOcbqX4ryJA6R7M6l50N3IiQQh5Y5TdrQiWWcNia 4S66J2yY9kt1UOGDqKMdzHzGEqtaFkyUQASpWE5lF2fqopg5f6ui8kEeO1dLzQM0+Esw fDVA== X-Gm-Message-State: AOAM533BTRvrWipKX1FigBlqB5JGUZYw9KOcGQRtlMuq/QsCql3ROu0e AqZwQa8lM0gWnb6OEQPlAG9uaEoqHE+iPdd2vzld9mKkaurX1xFywnM85Hy94my5MuZ1sryeVHA Dklan4/mCaHq+J6788Q== X-Received: by 2002:a05:622a:4f:b0:2e0:67f7:e760 with SMTP id y15-20020a05622a004f00b002e067f7e760mr33614682qtw.155.1648645006311; Wed, 30 Mar 2022 05:56:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOSp8OhJihkYbpE1F7KDnK/EePqZPlcoAtGyR0M3CbFO5oNZCtrF3lKdoDbFlOi3c6uwpZuw== X-Received: by 2002:a05:622a:4f:b0:2e0:67f7:e760 with SMTP id y15-20020a05622a004f00b002e067f7e760mr33614664qtw.155.1648645006046; Wed, 30 Mar 2022 05:56:46 -0700 (PDT) Received: from [192.168.1.130] (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id p8-20020a05620a22e800b0067e75955f5esm10510752qki.77.2022.03.30.05.56.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 05:56:45 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Wed, 30 Mar 2022 08:56:44 -0400 (EDT) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++: ICE with failed __is_constructible constraint [PR100474] In-Reply-To: <63ae6234-0e06-3b9b-f938-afb92cc5dbf6@redhat.com> Message-ID: References: <20220329192230.255163-1-ppalka@redhat.com> <63ae6234-0e06-3b9b-f938-afb92cc5dbf6@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.5 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_LOW, 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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 12:56:54 -0000 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? -- >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" } -- 2.35.1.693.g805e0a6808