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 44CFB3858C62 for ; Tue, 21 Nov 2023 22:20:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 44CFB3858C62 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 44CFB3858C62 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700605204; cv=none; b=leREEbcm5D3kH9pqxcQPSIVjJWV4xSqd/B5aMkElmKEElIc6keFALxl7HOweUcuz5qV59NWbc5NnlZaGp9UtgzrKQY2zL3/4AKIDBsh5aZ7/lTLW63lMTr1W6S2gJ44JIX+TW/JD6meHrj3lQYAFfKxo3yqfK0yARTPK86CmKhw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700605204; c=relaxed/simple; bh=1UXjdgmGl3ZyL7vt/lehZs3ENg/ZEcwda9C4WFr8ttY=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=UNx6gLAFIwDydW59l1uNg+KBTCm/4gsDK+2J3G/qHGFmG8IMwU1/y2pymtTpQi3uiDG2KQlv4CidZ6+5N/x0V8FW8na7I8sCR2RgAtFB5/XJAPx3k+RQpktrvO1zxlIIcxJakDlubtLZ6wotl4LjG5UPFaGJ/y0L2Uzwz7Xm1CQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700605202; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=43EnaeeG7VlAsGz6FfEml5X59x1Bic73EGj0298NWnQ=; b=FZ8USx8Z1d4CanAZW0p1KcVqBclY4pXTMqzcZ5w+u25UIyQuE+QHpzkGnQ1AyAhjL1rVRz fzlQPFQ6wjVwl7MVMYevBBPXCJwcOoIaHB2kn1VZ0+cu2vI34IZFxla1WMBNk0zUgPQJY+ ioRbquM+PZ22Fr0Y39VxbFG1siw+SFc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-387-Npop-NT6Ngenw0eiT2WSqg-1; Tue, 21 Nov 2023 17:20:01 -0500 X-MC-Unique: Npop-NT6Ngenw0eiT2WSqg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 683BC811E7B for ; Tue, 21 Nov 2023 22:20:00 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1219D1121306; Tue, 21 Nov 2023 22:19:59 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3ALMJvuB4135581 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 21 Nov 2023 23:19:58 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3ALMJvmn4135580; Tue, 21 Nov 2023 23:19:57 +0100 Date: Tue, 21 Nov 2023 23:19:56 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] c++, v3: Implement C++26 P2741R3 - user-generated static_assert messages [PR110348] Message-ID: Reply-To: Jakub Jelinek References: <4b133eec-f806-43af-800a-8339d50645fd@redhat.com> MIME-Version: 1.0 In-Reply-To: <4b133eec-f806-43af-800a-8339d50645fd@redhat.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, Nov 21, 2023 at 04:44:01PM -0500, Jason Merrill wrote: > > Or do you want to just use > > error_at (location, "% message must be a " > > "unevaluated string literal or object with " > > "% and % members"); > > wording (even when it is in C++26 term) regardless of the -std= level? > > No, I think "unevaluated string literal" will be confusing to users. I > guess it's fine as it is, let's just print the type (as commented inline > below). Ok. > > + error_at (location, "% message must be a string " > > + "literal or object with % and " > > + "% members"); > > Let's print the type of the message as well. so add " while it has type %qT", TREE_TYPE (message) or something else? > > + releasing_vec size_args, data_args; > > + message_sz = finish_call_expr (message_sz, &size_args, false, false, > > + tf_warning_or_error); > > + message_data = finish_call_expr (message_data, &data_args, false, false, > > + tf_warning_or_error); > > + if (message_sz == error_mark_node || message_data == error_mark_node) > > + return; > > + if (tree s > > + = cp_get_callee_fndecl_nofold (extract_call_expr (message_sz))) > > + if (!DECL_DECLARED_CONSTEXPR_P (s)) > > + warning_at (location, 0, "%qD used in % message " > > + "is not %", s); > > I don't think we need this check, it should be covered by the later > constant-expression checks. If the static_assert condition is true, we won't diagnose anything then. clang++ there incorrectly errors, but I thought a warning could be useful to users. Perhaps it could warn only if the condition is true? > > + error_at (location, "% message % " > > + "must be implicitly convertible to " > > + "%"); > > Let's also print the type of size(). " while it has type %qT" ? > > @@ -11485,9 +11544,96 @@ finish_static_assert (tree condition, tr > > if (processing_template_decl) > > goto defer; > > - int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT > > - (TREE_TYPE (TREE_TYPE (message)))); > > - int len = TREE_STRING_LENGTH (message) / sz - 1; > > + int len; > > + const char *msg = NULL; > > + char *buf = NULL; > > + if (message_sz && message_data) > > + { > > + tree msz > > + = fold_non_dependent_expr (message_sz, complain, > > + /*manifestly_const_eval=*/true); > > We can call cxx_constant_value here instead of fold_non_dependent_expr, > since we don't get here in a template. Ok. > > + t = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (t)), t); > > + tree t2 > > + = fold_non_dependent_expr (t, complain, > > + /*manifestly_const_eval=*/ > > + true); > > This can also be cxx_constant_value. > > > + if (!tree_fits_shwi_p (t2)) > > + { > > + cxx_constant_value (t); But in that case I don't have to call it again, right? > Let's add a comment here about how you're using (data(), 0) to test > core-constant. Ok. Jakub