Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
104 lines (86 sloc) 3.51 KB
<pre class="metadata">
Markup Shorthands: markdown yes
Group: WG21
Status: P
Shortname: P1276
Revision: 0
Audience: EWG
Title: Void Main
Editor: Isabella Muerte,
Date: 2018-09-15
Abstract: The current entrypoint for C++ is bizarre, special cased, and
Abstract: violates our own best practices. Let's make void a valid return type
Abstract: for main.
!Current Render: <a href="">P1276R0</a>
!Current Source: <a href="">slurps-mad-rips/papers/proposals/</a>
ins {background-color: #CCFFCC; text-decoration: underline;}
del {background-color: #FFCACA; text-decoration: line-through;}
# Revision History # {#changelog}
## Revision 0 ## {#r0}
Initial Release 🎉
# Motivation # {#motivation}
Main is a sweet special little gremlin in C++. It has interesting properties
regarding exceptions and noreturn functions, `argv` is actually deprecated on
some unicode aware platforms and it even lets us ignore the return type
entirely. And yet, this is the function we introduce to beginners from day one.
This magic, bizarre, entry point to our programs is a nightmare. This proposal
attempts to solve this, while also standardizing existing extensions *and*
archaic literature and examples.
This paper currently works in tandem with the [[p1275|Desert Sessions]]
proposal, which attempts to solve issues regarding `argv` and the lack of
modern support for reading from environment variables. However, it is not a
prerequisite of adding the [[p1275]] API into the standard, nor does [[p1275]]
require that this paper be added to the standard.
# Design # {#design}
The idea behind `void main()` is to simply state that a `main()` that takes no
arguments can choose to return nothing as well. Given that we currently permit
this *with* the `int` returning main signatures this will not break existing
# Wording # {#wording}
All wording is relative to [[N4762]]
In Section `main` function [**basic.start.main**] paragraph 2, insert
<sup>2</sup>An implementation shall not predefine the `main` function. This
function shall not be overloaded. Its type shall have C++ language linkage and
it have a declared return type of <ins>either</ins> type `int` <ins>or type
`void`</ins>, but otherwise its type is implementation-defined. An
implementation shall allow:
<ins><sup>(2.1)</sup>&mdash; a function of `()` returning `void` and</ins>
&mdash; a function of `()` returning `int` and
&mdash; a function of `(int`, pointer to pointer to `char)` returning `int`
In paragraph 5, insert:
<sup>5</sup>A `return` statement in `main` has the effect of leaving the main
function (destroying any objects with automatic storage duration) and calling
`std::exit` with the return value <ins>or `0` in the case of no return
value</ins> as the argument. If control flows off the end of the
*compound-statement* of `main`, the effect is equivalent to a `return` with
operand `0` (see also 13.3) <ins>, or calling `std::exit(0)` once `main`'s
scope has exited</ins>
<pre class=biblio>
"p1275": {
"authors": "Isabella Muerte",
"href": "",
"title": "Desert Sessions: Improving Hostile Environment Interactions"
You can’t perform that action at this time.