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 A0F633886C46 for ; Tue, 29 Mar 2022 20:53:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A0F633886C46 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-57-ScsJTvCJOTGtvhfL6aJabw-1; Tue, 29 Mar 2022 16:53:03 -0400 X-MC-Unique: ScsJTvCJOTGtvhfL6aJabw-1 Received: by mail-qk1-f198.google.com with SMTP id r11-20020a05620a03cb00b0067e0cd1c855so11339483qkm.4 for ; Tue, 29 Mar 2022 13:53:02 -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:references:from:in-reply-to :content-transfer-encoding; bh=voGNGcs2m4E/sJdXTwlnAPI6Bl7HYSAtx+qS4SyXkto=; b=5tH1qyiHiLD/WsUjaBvNgMbbIWJ4WxThJiirZ5uu+ofDOD1rHi7NexqJaxdR4heRpC 5EBwAxsXcxudRqjQoBJemqC2lV3a/d0iNaili4tUg8pe7CA4GUi74zu+Rut3veePSKc7 Jeoc7gQ/Mau8Bbwu+P3N3jsQ2GeFCVofipjtEacsYSLz3sEeCbFXudd9wTilakkAOjb4 xrQqUlBPJFA3Z+nmJBiR2ppbNmKz36nnT2/ZTZDpByffCKSQP/LPLevcwgZVZ3tdgfbM QASEmsnFYbGvQnruX+71J5eaY66R45SmBllY1ZUtSLHojTsIopk3l55mwJhN9ej/3+U4 HN0Q== X-Gm-Message-State: AOAM531ZB/LZjh+cxlJ8LGTj7IDdWeAOSmY7TCMO2LCqR3UD/2xNr5Za vUZ0V96MCcJv7CeaGY9kUerc4p1mXR7KVNxwq6mucXHBsT6+53rG5y+2yrNhG07z44dNAujsnQ5 Ca9CS1hkD7vkCCOyZGw== X-Received: by 2002:a05:622a:54f:b0:2e1:cc45:312a with SMTP id m15-20020a05622a054f00b002e1cc45312amr30400056qtx.435.1648587182411; Tue, 29 Mar 2022 13:53:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFBs77kIO3UNko1jAnNirHSXgUfk7pbpeCZF5JgpKI5HjRnZZM37xALmJlAimJZPITURrHSA== X-Received: by 2002:a05:622a:54f:b0:2e1:cc45:312a with SMTP id m15-20020a05622a054f00b002e1cc45312amr30400037qtx.435.1648587182020; Tue, 29 Mar 2022 13:53:02 -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 c10-20020ac87dca000000b002e1db1b7b10sm15784431qte.25.2022.03.29.13.53.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 29 Mar 2022 13:53:01 -0700 (PDT) Message-ID: <63ae6234-0e06-3b9b-f938-afb92cc5dbf6@redhat.com> Date: Tue, 29 Mar 2022 16:53:00 -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 , gcc-patches@gcc.gnu.org References: <20220329192230.255163-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20220329192230.255163-1-ppalka@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: 8bit X-Spam-Status: No, score=-12.9 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_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 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: Tue, 29 Mar 2022 20:53:07 -0000 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) : 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 %", > 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 > +concept C = __is_constructible(T, Args...); // { dg-message "evaluated to 'false'" } > +struct S { > + S() = delete; > +}; > + > +static_assert(C); // { dg-error "assert" }