Message ID | 20220329192230.255163-1-ppalka@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 61DE43865C2A for <patchwork@sourceware.org>; Tue, 29 Mar 2022 19:23:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61DE43865C2A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1648581793; bh=m8aq58F5THkMdwoITTyMWywNkPZqrtdXEsGasSVm8ng=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=vE6ZNzJ254VWg2NbAFFAYvYV41E2HHlCuwQdBOBNMlDYLb7Kie+ztXzdUqnW3y/iZ 9qzt13grMDKP3HQXmpVCu8lpfkBUBucWQuocpi39jGb7CF269gEEdMrXlTxXaSCSMI UJfQLZoaWHl79a08Y2QOyM7X7hkqSDS8LwzMjguA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 694523858C50 for <gcc-patches@gcc.gnu.org>; Tue, 29 Mar 2022 19:22:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 694523858C50 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.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-148--O8q4YN0NSOya4FbqBSzVA-1; Tue, 29 Mar 2022 15:22:34 -0400 X-MC-Unique: -O8q4YN0NSOya4FbqBSzVA-1 Received: by mail-qt1-f197.google.com with SMTP id y23-20020ac85257000000b002e06697f2ebso15590196qtn.16 for <gcc-patches@gcc.gnu.org>; Tue, 29 Mar 2022 12:22:34 -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:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=m8aq58F5THkMdwoITTyMWywNkPZqrtdXEsGasSVm8ng=; b=63+GihWvr74y20QxqGSJbB8AClYrhVv2BY+GR5NJeevyDpfQmgkvO1lIcXc0WmKlJQ ZHPiJqc7RpEe4K46JXxsIt8mFcdpsKQDG2J3mmEJS+L3z/xQU8/w/+Uxcc/t/fmMlVAO S50a7Np/sNYP53OsTIIFU7eUhQTxwdUsI+9Hojw3KDk2zMilKjhqHDTB4HWHmwOh3ZOj o+imiPx85FMVp63s/1zOmzUwBf2uZp6oXs42lzLfcvS7HYO9G3K3Ojhx0Xb6JVt7Ymge Aqhd6UtiM6hDtzLea/lkGO3hFveHHi31aqGgQzw3S8RWmtVCavHdbMSEW9O3bM/+5tcl ushQ== X-Gm-Message-State: AOAM531ElY12GGymlFHIweV2u2I+qE56Fch8ozbxlPbzkEPxXswuf0hs GXpdzqtXkrRHwFgjWjlWZS7g6Wdu83qteRwK1ZEDCX08xPP2wGomMj6DwzEe4SI9SKMyE7p227J Q++j9+ZzahLsd2rdklu0wTmzJpXsEHBB+9ZNE1qQUIwMb5zl6+mniiGaL7TW1KyguYZ0= X-Received: by 2002:a05:622a:1186:b0:2e1:b669:967 with SMTP id m6-20020a05622a118600b002e1b6690967mr29603848qtk.194.1648581753793; Tue, 29 Mar 2022 12:22:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxkUdbGPRHrsH79XrWcOFGzz/cH/4ND3ux6UvMPTlKTpI52gfMhBkhPy3CgwMcPB+QQyjryA== X-Received: by 2002:a05:622a:1186:b0:2e1:b669:967 with SMTP id m6-20020a05622a118600b002e1b6690967mr29603818qtk.194.1648581753470; Tue, 29 Mar 2022 12:22:33 -0700 (PDT) Received: from localhost.localdomain (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id x6-20020a376306000000b0067b32a8568esm10186210qkb.101.2022.03.29.12.22.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 12:22:32 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: ICE with failed __is_constructible constraint [PR100474] Date: Tue, 29 Mar 2022 15:22:30 -0400 Message-Id: <20220329192230.255163-1-ppalka@redhat.com> X-Mailer: git-send-email 2.35.1.677.gabf474a5dd MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-14.8 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_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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Patrick Palka via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Patrick Palka <ppalka@redhat.com> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
c++: ICE with failed __is_constructible constraint [PR100474]
|
|
Commit Message
Patrick Palka
March 29, 2022, 7:22 p.m. UTC
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? PR c++/100474 gcc/cp/ChangeLog: * constraint.cc (diagnose_trait_expr): Rename to ... (maybe_diagnose_trait_expr): ... this. Return a boolean indicating whether we handled the trait. (diagnose_atomic_constraint) <case TRAIT_EXPR>: Fall through to the default case if maybe_diagnose_trait_expr returns false. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-traits3.C: New test. --- gcc/cp/constraint.cc | 16 +++++++++------- gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C | 10 ++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C
Comments
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. > PR c++/100474 > > gcc/cp/ChangeLog: > > * constraint.cc (diagnose_trait_expr): Rename to ... > (maybe_diagnose_trait_expr): ... this. Return a boolean > indicating whether we handled the trait. > (diagnose_atomic_constraint) <case TRAIT_EXPR>: Fall through to > the default case if maybe_diagnose_trait_expr returns false. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/concepts-traits3.C: New test. > --- > gcc/cp/constraint.cc | 16 +++++++++------- > gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C | 10 ++++++++++ > 2 files changed, 19 insertions(+), 7 deletions(-) > 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..27b1b9bb659 100644 > --- a/gcc/cp/constraint.cc > +++ b/gcc/cp/constraint.cc > @@ -3567,10 +3567,10 @@ get_constraint_error_location (tree t) > return input_location; > } > > -/* Emit a diagnostic for a failed trait. */ > +/* Maybe emit a friendlier diagnostic for the failed trait. */ > > -static void > -diagnose_trait_expr (tree expr, tree args) > +static bool > +maybe_diagnose_trait_expr (tree expr, tree args) > { > location_t loc = cp_expr_location (expr); > > @@ -3655,8 +3655,9 @@ diagnose_trait_expr (tree expr, tree args) > inform (loc, " %qT is not a union", t1); > break; > default: > - gcc_unreachable (); > + return false; > } > + return true; > } > > /* Diagnose a substitution failure in the atomic constraint T using ARGS. */ > @@ -3685,9 +3686,6 @@ diagnose_atomic_constraint (tree t, tree args, tree result, sat_info info) > STRIP_ANY_LOCATION_WRAPPER (expr); > switch (TREE_CODE (expr)) > { > - case TRAIT_EXPR: > - diagnose_trait_expr (expr, args); > - break; > case REQUIRES_EXPR: > gcc_checking_assert (info.diagnose_unsatisfaction_p ()); > /* Clear in_decl before replaying the substitution to avoid emitting > @@ -3696,6 +3694,10 @@ diagnose_atomic_constraint (tree t, tree args, tree result, sat_info info) > info.in_decl = NULL_TREE; > tsubst_requires_expr (expr, args, info); > break; > + case TRAIT_EXPR: > + if (maybe_diagnose_trait_expr (expr, args)) > + break; > + /* Fall through. */ > default: > if (!same_type_p (TREE_TYPE (result), boolean_type_node)) > error_at (loc, "constraint %qE has type %qT, not %<bool%>", > 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..33152242988 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C > @@ -0,0 +1,10 @@ > +// PR c++/100474 > +// { dg-do compile { target c++20 } } > + > +template<class T, class... Args> > +concept C = __is_constructible(T, Args...); // { dg-message "evaluated to 'false'" } > +struct S { > + S() = delete; > +}; > + > +static_assert(C<S>); // { dg-error "assert" }
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 %<nothrow%> 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 %<nothrow%> default constructible", t1); + else + inform (loc, " %qT is not %<nothrow%> 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<class T> +concept Aggregate = __is_aggregate(T); +// { dg-message "'S' is not an aggregate" "" { target *-*-* } .-1 } + +template<class T> +concept TriviallyCopyable = __is_trivially_copyable(T); +// { dg-message "'S' is not trivially copyable" "" { target *-*-* } .-1 } + +template<class T, class U> +concept Assignable = __is_assignable(T, U); +// { dg-message "'S' is not assignable from 'int'" "" { target *-*-* } .-1 } + +template<class T, class U> +concept TriviallyAssignable = __is_trivially_assignable(T, U); +// { dg-message "'S' is not trivially assignable from 'int'" "" { target *-*-* } .-1 } + +template<class T, class U> +concept NothrowAssignable = __is_nothrow_assignable(T, U); +// { dg-message "'S' is not 'nothrow' assignable from 'int'" "" { target *-*-* } .-1 } + +template<class T, class... Args> +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<class T, class... Args> +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<class T, class... Args> +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<class T> +concept UniqueObjReps = __has_unique_object_representations(T); +// { dg-message "'S' does not have unique object representations" "" { target *-*-* } .-1 } + +static_assert(Aggregate<S>); // { dg-error "assert" } +static_assert(TriviallyCopyable<S>); // { dg-error "assert" } +static_assert(Assignable<S, int>); // { dg-error "assert" } +static_assert(TriviallyAssignable<S, int>); // { dg-error "assert" } +static_assert(NothrowAssignable<S, int>); // { dg-error "assert" } + +static_assert(Constructible<S>); // { dg-error "assert" } +static_assert(Constructible<S, int>); // { dg-error "assert" } +static_assert(Constructible<S, int, char>); // { dg-error "assert" } + +static_assert(TriviallyConstructible<S>); // { dg-error "assert" } +static_assert(TriviallyConstructible<S, int>); // { dg-error "assert" } +static_assert(TriviallyConstructible<S, int, char>); // { dg-error "assert" } + +static_assert(NothrowConstructible<S>); // { dg-error "assert" } +static_assert(NothrowConstructible<S, int>); // { dg-error "assert" } +static_assert(NothrowConstructible<S, int, char>); // { dg-error "assert" } + +static_assert(UniqueObjReps<S>); // { dg-error "assert" }
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 %<nothrow%> 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 %<nothrow%> default constructible", t1); > + else > + inform (loc, " %qT is not %<nothrow%> 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<class T> > +concept Aggregate = __is_aggregate(T); > +// { dg-message "'S' is not an aggregate" "" { target *-*-* } .-1 } > + > +template<class T> > +concept TriviallyCopyable = __is_trivially_copyable(T); > +// { dg-message "'S' is not trivially copyable" "" { target *-*-* } .-1 } > + > +template<class T, class U> > +concept Assignable = __is_assignable(T, U); > +// { dg-message "'S' is not assignable from 'int'" "" { target *-*-* } .-1 } > + > +template<class T, class U> > +concept TriviallyAssignable = __is_trivially_assignable(T, U); > +// { dg-message "'S' is not trivially assignable from 'int'" "" { target *-*-* } .-1 } > + > +template<class T, class U> > +concept NothrowAssignable = __is_nothrow_assignable(T, U); > +// { dg-message "'S' is not 'nothrow' assignable from 'int'" "" { target *-*-* } .-1 } > + > +template<class T, class... Args> > +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<class T, class... Args> > +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<class T, class... Args> > +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<class T> > +concept UniqueObjReps = __has_unique_object_representations(T); > +// { dg-message "'S' does not have unique object representations" "" { target *-*-* } .-1 } > + > +static_assert(Aggregate<S>); // { dg-error "assert" } > +static_assert(TriviallyCopyable<S>); // { dg-error "assert" } > +static_assert(Assignable<S, int>); // { dg-error "assert" } > +static_assert(TriviallyAssignable<S, int>); // { dg-error "assert" } > +static_assert(NothrowAssignable<S, int>); // { dg-error "assert" } > + > +static_assert(Constructible<S>); // { dg-error "assert" } > +static_assert(Constructible<S, int>); // { dg-error "assert" } > +static_assert(Constructible<S, int, char>); // { dg-error "assert" } > + > +static_assert(TriviallyConstructible<S>); // { dg-error "assert" } > +static_assert(TriviallyConstructible<S, int>); // { dg-error "assert" } > +static_assert(TriviallyConstructible<S, int, char>); // { dg-error "assert" } > + > +static_assert(NothrowConstructible<S>); // { dg-error "assert" } > +static_assert(NothrowConstructible<S, int>); // { dg-error "assert" } > +static_assert(NothrowConstructible<S, int, char>); // { dg-error "assert" } > + > +static_assert(UniqueObjReps<S>); // { dg-error "assert" }
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c5a991b9e71..27b1b9bb659 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3567,10 +3567,10 @@ get_constraint_error_location (tree t) return input_location; } -/* Emit a diagnostic for a failed trait. */ +/* Maybe emit a friendlier diagnostic for the failed trait. */ -static void -diagnose_trait_expr (tree expr, tree args) +static bool +maybe_diagnose_trait_expr (tree expr, tree args) { location_t loc = cp_expr_location (expr); @@ -3655,8 +3655,9 @@ diagnose_trait_expr (tree expr, tree args) inform (loc, " %qT is not a union", t1); break; default: - gcc_unreachable (); + return false; } + return true; } /* Diagnose a substitution failure in the atomic constraint T using ARGS. */ @@ -3685,9 +3686,6 @@ diagnose_atomic_constraint (tree t, tree args, tree result, sat_info info) STRIP_ANY_LOCATION_WRAPPER (expr); switch (TREE_CODE (expr)) { - case TRAIT_EXPR: - diagnose_trait_expr (expr, args); - break; case REQUIRES_EXPR: gcc_checking_assert (info.diagnose_unsatisfaction_p ()); /* Clear in_decl before replaying the substitution to avoid emitting @@ -3696,6 +3694,10 @@ diagnose_atomic_constraint (tree t, tree args, tree result, sat_info info) info.in_decl = NULL_TREE; tsubst_requires_expr (expr, args, info); break; + case TRAIT_EXPR: + if (maybe_diagnose_trait_expr (expr, args)) + break; + /* Fall through. */ default: if (!same_type_p (TREE_TYPE (result), boolean_type_node)) error_at (loc, "constraint %qE has type %qT, not %<bool%>", 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..33152242988 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-traits3.C @@ -0,0 +1,10 @@ +// PR c++/100474 +// { dg-do compile { target c++20 } } + +template<class T, class... Args> +concept C = __is_constructible(T, Args...); // { dg-message "evaluated to 'false'" } +struct S { + S() = delete; +}; + +static_assert(C<S>); // { dg-error "assert" }