diff options
author | Marek Polacek <polacek@redhat.com> | 2024-08-01 11:32:26 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2024-08-02 10:13:46 -0400 |
commit | a790828ccb3b06a7771f871651e7b54d13c3a168 (patch) | |
tree | 44e0f4f0e75b86e053fcb5f5ef17749d9783fe9a | |
parent | 00019b88e714c29c387a3f492155366c921474a0 (diff) | |
download | gcc-a790828ccb3b06a7771f871651e7b54d13c3a168.zip gcc-a790828ccb3b06a7771f871651e7b54d13c3a168.tar.gz gcc-a790828ccb3b06a7771f871651e7b54d13c3a168.tar.bz2 |
c++: DR882, main cannot be deleted [PR116169]
This DR clarifies that "int main() = delete;" is ill-formed.
PR c++/116169
gcc/cp/ChangeLog:
* decl.cc (cp_finish_decl): Disallow deleting ::main.
gcc/testsuite/ChangeLog:
* g++.dg/DRs/dr882.C: New test.
-rw-r--r-- | gcc/cp/decl.cc | 26 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/DRs/dr882.C | 5 |
2 files changed, 23 insertions, 8 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 279af21..687ae69 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -8649,15 +8649,25 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, && TREE_TYPE (init) == ridpointers[(int)RID_DELETE])) { /* FIXME check this is 1st decl. */ - DECL_DELETED_FN (decl) = 1; - DECL_DECLARED_INLINE_P (decl) = 1; - DECL_INITIAL (decl) - = TREE_CODE (init) == STRING_CST ? init : error_mark_node; - FOR_EACH_CLONE (clone, decl) + if (UNLIKELY (DECL_MAIN_P (decl))) { - DECL_DELETED_FN (clone) = 1; - DECL_DECLARED_INLINE_P (clone) = 1; - DECL_INITIAL (clone) = DECL_INITIAL (decl); + /* [basic.start.main]/3: A program that defines main as deleted + is ill-formed. */ + error ("%<::main%> cannot be deleted"); + DECL_INITIAL (decl) = NULL_TREE; + } + else + { + DECL_DELETED_FN (decl) = 1; + DECL_DECLARED_INLINE_P (decl) = 1; + DECL_INITIAL (decl) + = TREE_CODE (init) == STRING_CST ? init : error_mark_node; + FOR_EACH_CLONE (clone, decl) + { + DECL_DELETED_FN (clone) = 1; + DECL_DECLARED_INLINE_P (clone) = 1; + DECL_INITIAL (clone) = DECL_INITIAL (decl); + } } init = NULL_TREE; } diff --git a/gcc/testsuite/g++.dg/DRs/dr882.C b/gcc/testsuite/g++.dg/DRs/dr882.C new file mode 100644 index 0000000..c41cf7416 --- /dev/null +++ b/gcc/testsuite/g++.dg/DRs/dr882.C @@ -0,0 +1,5 @@ +// DR882 - Defining main as deleted +// PR c++/116169 +// { dg-do compile { target c++11 } } + +int main() = delete; // { dg-error "cannot be deleted" } |