From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13584 invoked by alias); 25 Apr 2018 14:40:14 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 13566 invoked by uid 89); 25 Apr 2018 14:40:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=proposing, para, Para, HContent-Transfer-Encoding:8bit X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 25 Apr 2018 14:40:11 +0000 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CFA403002F8A for ; Wed, 25 Apr 2018 14:40:09 +0000 (UTC) Received: from localhost (unknown [10.33.36.69]) by smtp.corp.redhat.com (Postfix) with ESMTP id 818B93142162; Wed, 25 Apr 2018 14:40:09 +0000 (UTC) Date: Wed, 25 Apr 2018 15:31:00 -0000 From: Jonathan Wakely To: Andrew Haley Cc: gcc@gcc.gnu.org Subject: Re: [RFC] Deprecate "implicit int" for main() in C++ Message-ID: <20180425144008.GU20930@redhat.com> References: <20180425122305.GS20930@redhat.com> <7039f928-e50b-1f75-4f71-70fda5873ab0@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7039f928-e50b-1f75-4f71-70fda5873ab0@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.1 (2017-09-22) X-SW-Source: 2018-04/txt/msg00166.txt.bz2 On 25/04/18 14:53 +0100, Andrew Haley wrote: >On 04/25/2018 01:23 PM, Jonathan Wakely wrote: > >> We enabled -Wreturn-type by default in GCC 8, so code using the >> extension will get warnings even without -Wall now. Users might want >> to use -Werror=return-type to ensure they aren't bitten by the new >> optimizations that assume control never reaches the end of a >> non-void function. > >But ISO C++ allows control to reach the end of main(), and >automagically returns 0. I guess you didn't mean that, but your reply >was confusing. > >N4659, Section 6.6.1 Para 5: > > If control flows off the end of the compound-statement of main, the > effect is equivalent to a return with operand 0 (see also 18.3). Yes, I should have said "never reaches the end of a non-void function other than main". -Wreturn-type doesn't warn about flowing off the end of main, because it's well-defined. There's definitely scope for confusion, because -Wreturn-type gives the main function special treatment in two ways: * Unlike normal functions, flowing off the end of main doesn't warn, because the standard defines what happens there. * Unlike normal functions, G++ allows omitting the return type of main. This is a non-standard extension to C++ (implicit int return types are allowed by C89 but not by any version of C++). What I'm proposing for deprecation is the non-standard extension that allows: main() { return 0; } More concretely, deprecating it for a few releases would allow us to apply the attached patch at some point in the future, so that instead of: rt.c:1:6: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type] main() { return 0; } ^ We'd get: rt.c:1:6: error: ISO C++ forbids declaration of 'main' with no type [-fpermissive] main() { return 0; } ^