[{"id":3677795,"web_url":"http://patchwork.ozlabs.org/comment/3677795/","msgid":"<a8afce31-a1fb-4057-a0fb-eb06a88e19de@redhat.com>","list_archive_url":null,"date":"2026-04-15T19:14:50","subject":"Re: [PATCH] c++: ICE with deleted main [PR120338]","submitter":{"id":4337,"url":"http://patchwork.ozlabs.org/api/people/4337/","name":"Jason Merrill","email":"jason@redhat.com"},"content":"On 4/15/26 2:35 PM, Marek Polacek wrote:\n> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/15?\n\nOK.\n\n> -- >8 --\n> Here we ICE with deleted main which is later redefined at\n> \n>    gcc_assert (DECL_SAVED_TREE (fn));\n> \n> because for some reason when deleting main I chose NULL_TREE instead of\n> error_mark_node as its DECL_INITIAL.  For other deleted functions we\n> also use error_mark_node so that\n> \n>    void foo() = delete;\n>    void foo() {}\n> \n> results in the \"redefinition of\" error.  Let's do the same for main, then.\n> \n> \tPR c++/120338\n> \n> gcc/cp/ChangeLog:\n> \n> \t* decl.cc (cp_finish_decl): Set DECL_INITIAL to error_mark_node\n> \tinstead of NULL_TREE for deleted main.\n> \n> gcc/testsuite/ChangeLog:\n> \n> \t* g++.dg/cpp0x/deleted19.C: New test.\n> ---\n>   gcc/cp/decl.cc                         | 2 +-\n>   gcc/testsuite/g++.dg/cpp0x/deleted19.C | 5 +++++\n>   2 files changed, 6 insertions(+), 1 deletion(-)\n>   create mode 100644 gcc/testsuite/g++.dg/cpp0x/deleted19.C\n> \n> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc\n> index 7e40226d739..679a8007ca6 100644\n> --- a/gcc/cp/decl.cc\n> +++ b/gcc/cp/decl.cc\n> @@ -9649,7 +9649,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,\n>   \t      /* [basic.start.main]/3: A program that defines main as deleted\n>   \t\t is ill-formed.  */\n>   \t      error (\"%<::main%> cannot be deleted\");\n> -\t      DECL_INITIAL (decl) = NULL_TREE;\n> +\t      DECL_INITIAL (decl) = error_mark_node;\n>   \t    }\n>   \t  else\n>   \t    {\n> diff --git a/gcc/testsuite/g++.dg/cpp0x/deleted19.C b/gcc/testsuite/g++.dg/cpp0x/deleted19.C\n> new file mode 100644\n> index 00000000000..c3f8f067748\n> --- /dev/null\n> +++ b/gcc/testsuite/g++.dg/cpp0x/deleted19.C\n> @@ -0,0 +1,5 @@\n> +// PR c++/120338\n> +// { dg-do compile { target c++11 } }\n> +\n> +int main() = delete;  // { dg-error \"cannot be deleted\" }\n> +int main() {}\t      // { dg-error \"redefinition\" }\n> \n> base-commit: 7cd246560ffcf0ffb9c64a4e9773011b74020e75","headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=iaeOU+T7;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=iaeOU+T7","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.129.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fwrSw4W5vz1yHM\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 16 Apr 2026 05:15:27 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 8F5944BA2E17\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 15 Apr 2026 19:15:25 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id 569E34BA2E0A\n for <gcc-patches@gcc.gnu.org>; Wed, 15 Apr 2026 19:14:55 +0000 (GMT)","from mail-qv1-f72.google.com (mail-qv1-f72.google.com\n [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-251-WfwYNkqZMBiteOoLlLowxg-1; Wed, 15 Apr 2026 15:14:53 -0400","by mail-qv1-f72.google.com with SMTP id\n 6a1803df08f44-8aca154e2b5so141451896d6.2\n for <gcc-patches@gcc.gnu.org>; Wed, 15 Apr 2026 12:14:53 -0700 (PDT)","from [192.168.50.130]\n (130-44-146-247.s12789.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com.\n [130.44.146.247]) by smtp.gmail.com with ESMTPSA id\n 6a1803df08f44-8ae6cbbc1bdsm17794486d6.38.2026.04.15.12.14.51\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Wed, 15 Apr 2026 12:14:51 -0700 (PDT)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 8F5944BA2E17","OpenDKIM Filter v2.11.0 sourceware.org 569E34BA2E0A"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 569E34BA2E0A","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 569E34BA2E0A","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776280495; cv=none;\n b=kiZbhyfnHBjTCpabY8kFc7ErAmh0sS5Z2Ap1pF8B5gsNPoRufBZi2KP3RnxYiU84ZLEjaFZRGDnS5F/nDKESfmmimf5TTYLWvpkZwrqGm4atCmBm34BszYECjxZCsRC+rr+w/tTiEOOvJF7BIROtYMZym62f+005fzS+fpedX/4=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776280495; c=relaxed/simple;\n bh=hq8KuWjALxbgrz+WMTIp7Se1apdWZrgedWwrMhDIcxg=;\n h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From;\n b=CFX5JdEF79NU6IA8wmL3uVcG4zPkFd8bc32y2ruWi1rpnbB7J9GUjKwi4Cl/kZPTTHyoQa/t07cDzULgq1VWiA9AfmDsAg/c9uIGGR3lqhU17bD2dv06lKxBnRscd22ArQE5VLma/05++12DPuNs7rqNAxZrycwS1BuZcOiioaY=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1776280495;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=xWrtK/GNHgNk/NTetKawdsAeCI7BGZtyq7QCcT3HwE8=;\n b=iaeOU+T7d4uUowxbn2GccexAiiSbpyohEby/UVJ+BISXgSqOZnl7g1qPnXDMeWmFJ5JRcB\n exLPPl7RQnaYfGgNU9sTcbpnu1X08+iP1aSIYjq1b91qxTCtSu22Lkez9ldfk48s6aVdoz\n nA8sZUyq1iW2fc+Xs+lF4XSl15sJ40c=","X-MC-Unique":"WfwYNkqZMBiteOoLlLowxg-1","X-Mimecast-MFC-AGG-ID":"WfwYNkqZMBiteOoLlLowxg_1776280492","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776280492; x=1776885292;\n h=content-transfer-encoding:in-reply-to:from:content-language\n :references:to:subject:user-agent:mime-version:date:message-id\n :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=xWrtK/GNHgNk/NTetKawdsAeCI7BGZtyq7QCcT3HwE8=;\n b=rOXOkM2orA6GRb9hXxkcqpzIINLLcnxCf/X+DTRaIl9Xxgya2P6dzxA7N2noBrxzwT\n tGY5ZcU5eG/fORPa10f8ETV4vWKCEuI2JgRdSEKt+yEElu6JUPHtTKE0ZCMljU/oGjck\n +sVLkayt9BqMbkf2InH18nuMPjsNA8vG2Ii6ttsd8oIj1tCidfgPhxDI9Zxh/yp1yjKX\n HXbcK7/E8Pg7Egt8HYMwg88mGEX8CHlpxhG+yj4sCNk0rqTVar72QE6kQriG68OY/AoT\n jCPK5m4ixIL2pzD53YRTluORUuVFhzBkE5PjbdslmbMqyAhKvckkB8bemZKi5Ms7LXtL\n dVmg==","X-Forwarded-Encrypted":"i=1;\n AFNElJ8Fj2Eih9nPhGNDlEnytFO+h5C/i3f4hlWbwr3YAYe1+l9qnk/EkT+i8NIKvy58u6p7V45Qbwqx1WRL4Q==@gcc.gnu.org","X-Gm-Message-State":"AOJu0Yz6MJQjgtpgYF0S4eKNTaHjACHEIqEBktnCsK6qEj3hXuB2T4Kj\n 1enuQc9bUF8CrOZ7EkMW+oYCR05q/jPjGPDUHB9IV/UnTobZ1+/r0+qXlBL87gzjxtdiFZX21Tw\n loN60rQnhq1lajR/I9bmxSgjUk/FhK/64KO9fqfEQ4f1ApbXeQJev0P/Yx+o=","X-Gm-Gg":"AeBDiestKoFrJQ8u/QuJs/qz8uaqYQmoj7VXCrfc5YaSzLFX0yLrRqsjSSTAsm8TxUS\n sAT2OjTIeujE1IaItW7kI2u2UTGV1l0x7uTvux31AR3tKtsucLh/Ye1CK5CIwvkAMtgYh6z8PNG\n CfNpHlnKxhMU0HJn+iXcj96BD7SMJB+BZWWjC/ouCDMceKyg5u/LK/YvsU4Bir3jwbZd5ty1F+H\n JONgeFJVK/aWnk3QKKRQW6+2nVN4OHbzCOq3L2vEaXXwbMSN3rAJQ5mMrADSV33lkEW/xtVsn3z\n iCDRo85TPZkYK/WPZ5r8zhK928d6u77DFv55IjQdYgVPWkPWvpVi8LsK6vUW8jIuvF6D3VZbyMq\n +dHG35+vF6dZ4mo6vX3hPdlWju0WPj3A+kIH68A5lbhaOhrkdp96CJ67h7Y4HpMloiO3wklUdXw\n z897+A9Bkg7BEf59b3Tmt+09qj9ilSqHHTmJMfNI+/Rg==","X-Received":["by 2002:a05:6214:2dc6:b0:8a4:21d9:bbef with SMTP id\n 6a1803df08f44-8ac8615445cmr387625876d6.2.1776280492521;\n Wed, 15 Apr 2026 12:14:52 -0700 (PDT)","by 2002:a05:6214:2dc6:b0:8a4:21d9:bbef with SMTP id\n 6a1803df08f44-8ac8615445cmr387625326d6.2.1776280492062;\n Wed, 15 Apr 2026 12:14:52 -0700 (PDT)"],"Message-ID":"<a8afce31-a1fb-4057-a0fb-eb06a88e19de@redhat.com>","Date":"Wed, 15 Apr 2026 15:14:50 -0400","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] c++: ICE with deleted main [PR120338]","To":"Marek Polacek <polacek@redhat.com>, GCC Patches\n <gcc-patches@gcc.gnu.org>, Patrick Palka <ppalka@redhat.com>","References":"<20260415183539.1303758-1-polacek@redhat.com>","From":"Jason Merrill <jason@redhat.com>","In-Reply-To":"<20260415183539.1303758-1-polacek@redhat.com>","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"t935rOqAcgeFic4uQrdctTnk8SsnEEIMzFxoU_65Zmk_1776280492","X-Mimecast-Originator":"redhat.com","Content-Language":"en-US","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}}]