From: Marek Polacek Date: Wed, 15 Apr 2026 18:15:06 +0000 (-0400) Subject: c++: ICE with deleted main [PR120338] X-Git-Tag: basepoints/gcc-17~115 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77d4080e1e5f9d467816e2e2e878edbfbb7ee1c1;p=thirdparty%2Fgcc.git c++: ICE with deleted main [PR120338] Here we ICE with deleted main which is later redefined at gcc_assert (DECL_SAVED_TREE (fn)); because for some reason when deleting main I chose NULL_TREE instead of error_mark_node as its DECL_INITIAL. For other deleted functions we also use error_mark_node so that void foo() = delete; void foo() {} results in the "redefinition of" error. Let's do the same for main, then. PR c++/120338 gcc/cp/ChangeLog: * decl.cc (cp_finish_decl): Set DECL_INITIAL to error_mark_node instead of NULL_TREE for deleted main. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/deleted19.C: New test. Reviewed-by: Jason Merrill --- diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 7e40226d739..679a8007ca6 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -9649,7 +9649,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, /* [basic.start.main]/3: A program that defines main as deleted is ill-formed. */ error ("%<::main%> cannot be deleted"); - DECL_INITIAL (decl) = NULL_TREE; + DECL_INITIAL (decl) = error_mark_node; } else { diff --git a/gcc/testsuite/g++.dg/cpp0x/deleted19.C b/gcc/testsuite/g++.dg/cpp0x/deleted19.C new file mode 100644 index 00000000000..c3f8f067748 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/deleted19.C @@ -0,0 +1,5 @@ +// PR c++/120338 +// { dg-do compile { target c++11 } } + +int main() = delete; // { dg-error "cannot be deleted" } +int main() {} // { dg-error "redefinition" }