From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7948) id EA8833858D35; Tue, 23 Apr 2024 06:00:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA8833858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713852032; bh=XobUG0VkNHi2CuU+Lrtp2SsZ21Gf+Gk+LAwWJpEfiVE=; h=From:To:Subject:Date:From; b=HOgkLtRGW6R3KPEeBFFljN4mMZVUTdcw3cKe7AL2osMbPuXOyiCiSGchOqxgNqzl9 cHmEsJTWPb0376zQgfHLU7inqvlDLRCZ0qr7xDCCcI3hi69Fg0iTJwrlTf5nkqWIbq oB+qaFpxKNK2A7xvsXHgMo2cp527cU+Op40Z78ng= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Nathaniel Shead To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-10085] c++: Check if allocation functions are xobj members [PR114078] X-Act-Checkin: gcc X-Git-Author: Nathaniel Shead X-Git-Refname: refs/heads/master X-Git-Oldrev: 77e114bb0dc03d1df7f84221e3132d19030c34b4 X-Git-Newrev: cf51fe706ea0219beb5bb85e81606d372ca9635e Message-Id: <20240423060032.EA8833858D35@sourceware.org> Date: Tue, 23 Apr 2024 06:00:32 +0000 (GMT) List-Id: https://gcc.gnu.org/g:cf51fe706ea0219beb5bb85e81606d372ca9635e commit r14-10085-gcf51fe706ea0219beb5bb85e81606d372ca9635e Author: Nathaniel Shead Date: Sat Apr 20 15:08:02 2024 +1000 c++: Check if allocation functions are xobj members [PR114078] A class allocation member function is implicitly 'static' by [class.free] p3, so cannot have an explicit object parameter. PR c++/114078 gcc/cp/ChangeLog: * decl.cc (grokdeclarator): Check allocation functions for xobj parameters. gcc/testsuite/ChangeLog: * g++.dg/cpp23/explicit-obj-ops-alloc.C: New test. Signed-off-by: Nathaniel Shead Diff: --- gcc/cp/decl.cc | 6 ++++++ gcc/testsuite/g++.dg/cpp23/explicit-obj-ops-alloc.C | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 65ab64885ff..2af026d255d 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -13728,6 +13728,12 @@ grokdeclarator (const cp_declarator *declarator, inform (DECL_SOURCE_LOCATION (xobj_parm), "explicit object parameter declared here"); } + if (unqualified_id + && identifier_p (unqualified_id) + && IDENTIFIER_NEWDEL_OP_P (unqualified_id)) + error_at (DECL_SOURCE_LOCATION (xobj_parm), + "%qD cannot be an explicit object member " + "function", unqualified_id); } } tree pushed_scope = NULL_TREE; diff --git a/gcc/testsuite/g++.dg/cpp23/explicit-obj-ops-alloc.C b/gcc/testsuite/g++.dg/cpp23/explicit-obj-ops-alloc.C new file mode 100644 index 00000000000..8a277db7ef5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/explicit-obj-ops-alloc.C @@ -0,0 +1,11 @@ +// PR c++/114078 +// { dg-do compile { target c++23 } } + +using size_t = decltype(sizeof(0)); + +struct S { + void* operator new(this size_t); // { dg-error "explicit object" } + void* operator new[](this size_t); // { dg-error "explicit object" } + void operator delete(this void*); // { dg-error "explicit object" } + void operator delete[](this void*); // { dg-error "explicit object" } +};