From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id 172453858D28 for ; Thu, 29 Sep 2022 09:22:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 172453858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x629.google.com with SMTP id rk17so1548554ejb.1 for ; Thu, 29 Sep 2022 02:22:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=v5W4Loc4Ifeauwve617F5htQTJve1bNQSE+nWVzlXqg=; b=AO6AJxpif/3UvPk6wrGYuPMfpUfyZZ8T26fibbGuyIH4bbtTQO7bl3Cj+K03m2M28Q AWwVuZRSUlknkGi0Z0aqNvJHXEqRYRoFzpFrmDBTwEGkIfpUIHdx8PgZUdTi/hsvNRom jvU2RqcqVtbPNpAbPKuHpjPdhb+8HnTnKWa1Hw1cI3o8UJL1UbQCNy/SptRyEReEMjiz KrZ7hOkNbY36Qz/61QZBaX8q69EzAGGtiV2rCiI5oLFsLDxW/6uWr0lKVBNOYMgPkpQE nI/Omv8QPik31lpAmyhsFPf6y9R+ph9ZrszblIeXhjmu4uHu9ZusCPSVQv2k8tPEIrr8 uuhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=v5W4Loc4Ifeauwve617F5htQTJve1bNQSE+nWVzlXqg=; b=Zdsc/7Kpkx6iGSNYD/Bcci3BwgrQ39j1S6VcjpbV4ETjveJrnuf2Wj/NecMzfJJHGF xVsHuyJpSDobHlLEkFKTXWd1haAN9Sflj19ACKHfCC1QfQYFeBMbVHWXAoex1zvYVqil 3H+RtB3d8hxBssBqgB97Y8ZC2+Q+Hig+T8nlg5YV1Sel6/Hb2eZ0pLWFkgBXp1onVt9m eMzOOVJhhojt7fku0vaWG7Dl/KBNiJjJ/zpH6Rci+XTrMGjJLaqgCVAgQy8Zrd3vusvl TBFCH4Jw//w78CM4dATfyjaB7k3TkjJAZLYR4KRpM46bOjfb88mBsxWUa3ykbe8e3NzZ sPFw== X-Gm-Message-State: ACrzQf15Lm3mUaPZMRwL3Z5DBC+ljp6Fgsox3kDGO0mM3SKrMw762hDH YXL1wUx6Sc5xxKHiQZBAxWLn+ZFgiLczXBKIGA4= X-Google-Smtp-Source: AMsMyM5ntHohAVCyR2MmtpZAYXqTgYTClbTvgGpvB1B72r1GBdjezVyUYZFUvfwCyIJQaqNtdjB2w0U4NWQcaXT2n8o= X-Received: by 2002:a17:906:30c5:b0:782:707:9e2d with SMTP id b5-20020a17090630c500b0078207079e2dmr1885935ejb.286.1664443323971; Thu, 29 Sep 2022 02:22:03 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Thu, 29 Sep 2022 10:21:52 +0100 Message-ID: Subject: Re: Handling of main() function for freestanding To: Jakub Jelinek Cc: Richard Biener , "gcc@gcc.gnu.org" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, 29 Sept 2022 at 08:12, Jakub Jelinek wrote: > > On Thu, Sep 29, 2022 at 08:00:15AM +0200, Richard Biener via Gcc wrote: > > On Wed, Sep 28, 2022 at 10:17 PM Jonathan Wakely via Gcc > > wrote: > > > > > > As part of implementing a C++23 proposal [1] to massively increase the > > > scope of the freestanding C++ standard library some questions came up > > > about the special handling of main() that happens for hosted > > > environments. > > > > > > As required by both C++ (all versions) and C (since C99), falling off > > > the end of the main() function is not undefined, the compiler is > > > required to insert an implicit 'return 0' [2][3]. However, this > > > special handling only applies to hosted environments. For freestanding > > > the return type or even the existence of main is > > > implementation-defined. > > ^^^^^^^^^^^^^^^^^^^^^^ > > > > so just document that 'int main(int, char **)' is special to GCC even in > > freestanding environments and do not emit -Wreturn-type diagnostics? > > I think that's entirely reasonable (but of course make sure to add > > an implicit return 0; then as well) > > -fspecial-main is weirdly named, I wonder if we couldn't do the > above by default and have -fno-builtin-main turn that special behavior > off (in that case then don't append return 0 and emit -Wreturn-type > diagnostics). Not all our builtins are about whether we expand them inline, but > about whether we apply special handling to those functions, assume special > properties etc. Just -fno-builtin shouldn't imply -fno-builtin-main... Yeah, that sounds like a good compromise. Make int main do the right thing by default, but offer a switch to restore the current behaviour for anybody who really wants it.