public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Jonathan Wakely <jwakely@redhat.com>
Cc: Andrew Haley <aph@redhat.com>, gcc Mailing List <gcc@gcc.gnu.org>
Subject: Re: [RFC] Deprecate "implicit int" for main() in C++
Date: Wed, 25 Apr 2018 15:54:00 -0000	[thread overview]
Message-ID: <CADzB+2meKVEj4khyybL4ymFaLGqHk4-YEv9ZUgLKFAFa685pUQ@mail.gmail.com> (raw)
In-Reply-To: <20180425144008.GU20930@redhat.com>

On Wed, Apr 25, 2018 at 10:40 AM, Jonathan Wakely <jwakely@redhat.com> wrote:
> 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; }
>      ^

I'm still not sure what the advantage is of changing the warning to an
error, but I suppose I wouldn't object either.

Jason

  reply	other threads:[~2018-04-25 15:48 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-25 13:12 Jonathan Wakely
2018-04-25 13:57 ` Andrew Haley
2018-04-25 13:59   ` Jason Merrill
2018-04-25 14:04     ` Andrew Haley
2018-04-25 14:40       ` Jonathan Wakely
2018-04-25 15:48         ` Andrew Haley
2018-04-25 16:22           ` Jonathan Wakely
2018-04-25 16:45             ` David Malcolm
2018-04-25 17:13               ` Jonathan Wakely
2018-04-25 17:50                 ` Nathan Sidwell
2018-04-25 21:14                   ` Jonathan Wakely
2018-04-25 15:31   ` Jonathan Wakely
2018-04-25 15:54     ` Jason Merrill [this message]
2018-05-08 11:36     ` Florian Weimer
2018-05-08 11:39       ` Jonathan Wakely
2018-05-08 12:02       ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADzB+2meKVEj4khyybL4ymFaLGqHk4-YEv9ZUgLKFAFa685pUQ@mail.gmail.com \
    --to=jason@redhat.com \
    --cc=aph@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=jwakely@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).