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 E3CF33853D5D for ; Thu, 17 Nov 2022 18:38:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E3CF33853D5D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668710313; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=72kyylUAJre+C07vU14fj37IL/gPhEMZ5o/giSchT88=; b=K2bXqA2ZX86niF45Wq3HlhH94CKvDExgc+cm6C1Dg0tDbVgJYDJqr9txWfw0kjYZZCpE98 CM69xoF/WISN4q5IWCPqAunwAV3/ZGRRvsZbzi4TE//EGuHsGyUkl7V6eGiQSIgIBjrrYi kCh4xxluvomlxxmntzEIEr1ySfquDbc= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-472-37PjgXPvM5uRME8cLQfrgw-1; Thu, 17 Nov 2022 13:38:32 -0500 X-MC-Unique: 37PjgXPvM5uRME8cLQfrgw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0AE551C05EB3 for ; Thu, 17 Nov 2022 18:38:32 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.10.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3205111DCE7; Thu, 17 Nov 2022 18:38:31 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: constinit on pointer to function [PR104066] Date: Thu, 17 Nov 2022 13:38:10 -0500 Message-Id: <20221117183810.33353-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=-12.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_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP 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: [dcl.constinit]: "The constinit specifier shall be applied only to a declaration of a variable with static or thread storage duration." Thus, this ought to be OK: constinit void (*p)() = nullptr; but the error message I introduced when implementing constinit was not looking at funcdecl_p, so the code above was rejected. Fixed thus. I'm checking constinit_p first because I think that's far more likely to be false than funcdecl_p. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? I think I'd like to backport this all the way back to 10. PR c++/104066 gcc/cp/ChangeLog: * decl.cc (grokdeclarator): Check funcdecl_p before complaining about constinit. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/constinit18.C: New test. --- gcc/cp/decl.cc | 2 +- gcc/testsuite/g++.dg/cpp2a/constinit18.C | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/constinit18.C diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index d28889ed865..9a7b1a6c381 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -13071,7 +13071,7 @@ grokdeclarator (const cp_declarator *declarator, "an array", name); return error_mark_node; } - if (constinit_p) + if (constinit_p && funcdecl_p) { error_at (declspecs->locations[ds_constinit], "% on function return type is not " diff --git a/gcc/testsuite/g++.dg/cpp2a/constinit18.C b/gcc/testsuite/g++.dg/cpp2a/constinit18.C new file mode 100644 index 00000000000..51b4f0273be --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/constinit18.C @@ -0,0 +1,12 @@ +// PR c++/104066 +// { dg-do compile { target c++20 } } + +constinit void (*p)() = nullptr; +constinit void (*pp)() = nullptr; +void fn(); +constinit void (&r)() = fn; + +extern constinit long (* const syscall_reexported) (long, ...); + +constinit void bad (); // { dg-error ".constinit. on function return type is not allowed" } +constinit void bad () { } // { dg-error ".constinit. on function return type is not allowed" } base-commit: ee892832ea19b21a3420ef042e582204fac852a2 -- 2.38.1