]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Implement C++26 P2573R2 - = delete("should have a reason"); [PR114458] master trunk
authorJakub Jelinek <jakub@redhat.com>
Thu, 2 May 2024 07:34:31 +0000 (09:34 +0200)
committerJakub Jelinek <jakub@redhat.com>
Thu, 2 May 2024 07:34:31 +0000 (09:34 +0200)
commit2f15787f2e1a3afe2c2ad93d4eb0d3c1f73c8fbd
tree10da576af5ac3754ece3147a1ddb8224c7f205ad
parentc59708fba3f98a4cc257741b88216b6caf6b4a87
c++: Implement C++26 P2573R2 - = delete("should have a reason"); [PR114458]

The following patch implements the C++26 P2573R2
= delete("should have a reason"); paper.
I've tried to avoid increasing compile time memory for it when it isn't
used (e.g. by adding a new lang_decl tree member), so the reason is
represented as STRING_CST in DECL_INITIAL (which normally is for
DECL_DELETED_FN error_mark_node) and to differentiate this delete("reason")
initializer from some bogus attempt to initialize a function with "reason"
using the RID_DELETE identifier as TREE_TYPE of the STRING_CST, as nothing
needs to care about the type of the reason.  If preferred it could
be say TREE_LIST with the reason STRING_CST and RID_DELETE identifier or
something similar instead, but that would need more compile time memory when
it is used.

2024-05-02  Jakub Jelinek  <jakub@redhat.com>

PR c++/114458
gcc/c-family/
* c-cppbuiltin.cc (c_cpp_builtins): Predefine
__cpp_deleted_function=202403L for C++26.
gcc/cp/ChangeLog
* parser.cc (cp_parser_pure_specifier): Implement C++26 P2573R2
- = delete("should have a reason");.  Parse deleted-function-body.
* decl.cc (duplicate_decls): Copy DECL_INITIAL from DECL_DELETED_FN
olddecl to newdecl if it is a STRING_CST.
(cp_finish_decl): Handle deleted init with a reason.
* decl2.cc: Include "escaped_string.h".
(grokfield): Handle deleted init with a reason.
(mark_used): Emit DECL_DELETED_FN reason in the message if any.
* cp-tree.h (DECL_DELETED_FN): Document representation of
= delete("reason") on a DECL.
gcc/testsuite/
* g++.dg/cpp26/feat-cxx26.C (__cpp_deleted_function): Add test.
* g++.dg/cpp26/delete-reason1.C: New test.
* g++.dg/cpp26/delete-reason2.C: New test.
* g++.dg/parse/error65.C (f1): Adjust expected diagnostics.
gcc/c-family/c-cppbuiltin.cc
gcc/cp/cp-tree.h
gcc/cp/decl.cc
gcc/cp/decl2.cc
gcc/cp/parser.cc
gcc/testsuite/g++.dg/cpp26/delete-reason1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp26/delete-reason2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp26/feat-cxx26.C
gcc/testsuite/g++.dg/parse/error65.C