public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Check if allocation functions are xobj members [PR114078]
@ 2024-04-20  8:39 Nathaniel Shead
  2024-04-22  2:59 ` Patrick Palka
  0 siblings, 1 reply; 3+ messages in thread
From: Nathaniel Shead @ 2024-04-20  8:39 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

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 <nathanieloshead@gmail.com>
---
 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" }
+};
-- 
2.43.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] c++: Check if allocation functions are xobj members [PR114078]
  2024-04-20  8:39 [PATCH] c++: Check if allocation functions are xobj members [PR114078] Nathaniel Shead
@ 2024-04-22  2:59 ` Patrick Palka
  2024-04-23  3:15   ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Palka @ 2024-04-22  2:59 UTC (permalink / raw)
  To: Nathaniel Shead; +Cc: gcc-patches, Jason Merrill

On Sat, 20 Apr 2024, Nathaniel Shead wrote:

> 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.

LGTM

> 
> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> ---
>  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" }
> +};
> -- 
> 2.43.2
> 
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] c++: Check if allocation functions are xobj members [PR114078]
  2024-04-22  2:59 ` Patrick Palka
@ 2024-04-23  3:15   ` Jason Merrill
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2024-04-23  3:15 UTC (permalink / raw)
  To: Patrick Palka, Nathaniel Shead; +Cc: gcc-patches

On 4/21/24 19:59, Patrick Palka wrote:
> On Sat, 20 Apr 2024, Nathaniel Shead wrote:
> 
>> 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.
> 
> LGTM

Agreed, OK.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-23  3:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-20  8:39 [PATCH] c++: Check if allocation functions are xobj members [PR114078] Nathaniel Shead
2024-04-22  2:59 ` Patrick Palka
2024-04-23  3:15   ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).