From patchwork Sat Apr 20 08:39:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1925831 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=mPEVy39+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VM4hY117tz1yPJ for ; Sat, 20 Apr 2024 18:40:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5D03B385840A for ; Sat, 20 Apr 2024 08:40:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by sourceware.org (Postfix) with ESMTPS id 276C73858D33 for ; Sat, 20 Apr 2024 08:39:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 276C73858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 276C73858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::102c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713602394; cv=none; b=rVOgbGx9KeI6ZdpBxRL5/D5BlJ1XjkJFXfZduryy6zx/KBBsibYAONn0i3RLbdh8pnCXRZKstWyJLB1YvqN2P+xcdvTHlN9S+uLWRrtBSxXRTyOkeFGu39ERAGbAMChJx/4DrSdNJgWQu4d3ZsElAS+TzhMr/4hr0A0+mYJrr+c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713602394; c=relaxed/simple; bh=b057CvQKyrCRujxlwHOM1zKbX2acwfYyKcXbBZCZD9c=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=QOo8c60226Osw0EeP2Bne+F5SOVYd30M7IGLk7fFkVpgLJWWqDhb5lmCSf9VJjlobuE0MTQpaAGSejKYKdbsS+kPOkaOB8w3mfsV9xHEP+bD0QIo9bsmGDSwexTbUB66QSDUbUZqOYQDl6FvZA43LJAitkSNkvyZD8y0dCKvLqg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-2abf9305afcso1623080a91.1 for ; Sat, 20 Apr 2024 01:39:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713602390; x=1714207190; darn=gcc.gnu.org; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=MEqwJv3lRZPZXvwoXLU7drkimFQiHeRTIj5TxEjZhPs=; b=mPEVy39+2xBgitzc8BFQWfO+blc2xkI/B1j8MnD0JfbqQXY1TwGo5hTzXkohh0KEsc vla+5mc45l98Q/8F8KpkxKy46OZBP4CXTWdWY6g6jTNihGZiC5t/blQ+Sj/xLTLre31l cceItxmhXsE9d1A4sqi0xMSiBZebW8hY0Tg+BJeIB87uTweJoMBAr60lXiOi8YKdcE6/ wDaLxWT9e6js3/p62kP3UGyZjEGB+IyEbTEoeUfD3M/H1k1pjF0ANxs9sfHhdJhvq84/ 9hFzVwSIJ5n6sCAx+E0QFMC4We1W8nH8L0lb1Apvis7c9+fGHvxRCkyOz+BlrArbZNEz ugkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713602390; x=1714207190; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MEqwJv3lRZPZXvwoXLU7drkimFQiHeRTIj5TxEjZhPs=; b=M3t7McSJIpPC7QNOnQiuvBJMyNm897Y2lKJw7RMOL5r4BZ80gNdeQVtOov2gDpIygM lDSt1o2uM9k+tAFJBxnJINTVmU+mnTrp9yTSVavhXONsWTnyecOWwy9EsQktv/zL0+tW r1y/YjRSlLKNaDnLyUpChN4HtBeFrc9R0LmqXT6Mbt2BCgzNElQns9zlMeHAq2TShZxY RkAfvDyaScowCRoOB6teEaM5+XTz/4ig9jTRb2rIN/hUUuTKCgORHR23PdQKaHuExarN 32g/DBv+aaqbd7t8Nge3V1HgI7HzEMctnx2aYc03yNfo9qw2jMXpgq1gmv6FD2RIzPWR g9hQ== X-Gm-Message-State: AOJu0YxOiYvHY74gMq1sJt2LF3qPJpFUrFT+imyXvJOoIW38+lg+tEor vV9Ebymhl58tiwzSYKTjRYiGwBWK7VmLyVE5AoNL6ip8/SYB/p4xG5dw4Q== X-Google-Smtp-Source: AGHT+IGGHfM1dPgckPPYkiY6FUtYDQhHgfkxl5U/Q+gcfGn8NRSvKyMmmMVtcWoYELb2d2w30McEcw== X-Received: by 2002:a17:90b:3a89:b0:2a6:4293:f88c with SMTP id om9-20020a17090b3a8900b002a64293f88cmr3715933pjb.16.1713602390049; Sat, 20 Apr 2024 01:39:50 -0700 (PDT) Received: from Thaum. (121-44-11-123.tpgi.com.au. [121.44.11.123]) by smtp.gmail.com with ESMTPSA id u14-20020a17090ac88e00b002abb4500e97sm4379494pjt.41.2024.04.20.01.39.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Apr 2024 01:39:49 -0700 (PDT) Message-ID: <66237f55.170a0220.88a25.0553@mx.google.com> X-Google-Original-Message-ID: Date: Sat, 20 Apr 2024 18:39:45 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill Subject: [PATCH] c++: Check if allocation functions are xobj members [PR114078] MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? -- >8 -- 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 --- gcc/cp/decl.cc | 6 ++++++ gcc/testsuite/g++.dg/cpp23/explicit-obj-ops-alloc.C | 11 +++++++++++ 2 files changed, 17 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp23/explicit-obj-ops-alloc.C 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" } +};