From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1734) id 8D2083858004; Fri, 18 Nov 2022 00:45:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D2083858004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668732338; bh=wGqRQNjDRr9BROyh4sIc5jY2VV28bg4TTxFwTclxvA8=; h=From:To:Subject:Date:From; b=xxUdzCdN20+Hsai7CvRa6nJinf/1QOfNMBWMET2+DSju0hYdC9YAVlPezdgXgYSKx DoALRrv2Ks+MB/MjoRnfs4OzUriZvDRaShuVuMXhigP7Urjmz/vRfPfRqFX4eoRyBt DZ+0rS/z3BIufToy7voM6di1uoNe274naphKWqFM= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marek Polacek To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-10381] c++: constinit on pointer to function [PR104066] X-Act-Checkin: gcc X-Git-Author: Marek Polacek X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: ac5ea7e672f4d98395f2e8910e7e2886050f3713 X-Git-Newrev: 90824f6c57e1ac7b94c558b4c99721b412df75ef Message-Id: <20221118004538.8D2083858004@sourceware.org> Date: Fri, 18 Nov 2022 00:45:38 +0000 (GMT) List-Id: https://gcc.gnu.org/g:90824f6c57e1ac7b94c558b4c99721b412df75ef commit r11-10381-g90824f6c57e1ac7b94c558b4c99721b412df75ef Author: Marek Polacek Date: Thu Nov 17 11:59:29 2022 -0500 c++: constinit on pointer to function [PR104066] [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. PR c++/104066 gcc/cp/ChangeLog: * decl.c (grokdeclarator): Check funcdecl_p before complaining about constinit. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/constinit18.C: New test. (cherry picked from commit 7b3b2f50953c5143d4b14b59d322d8a793f411dd) Diff: --- gcc/cp/decl.c | 2 +- gcc/testsuite/g++.dg/cpp2a/constinit18.C | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 514d4c1bc20..6c07cc2ad61 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -12682,7 +12682,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" }