The first is probably legal. The other two certainly not
(§7.1.6.4/1): "The auto type-specifier signifies that the type
of a variable being declared shall be deduced from its
initializer or that a function declarator shall include
a trailing-return-type."
I say probably for the first, because §3.6.1 isn't really clear
to what degree the definition must match. A 100% textual match
isn't required, even if that is what a literal interpretation of
what it says would imply: in the text, the body of main
is
given as /* ... */
, which isn't very useful, and certainly
isn't required. Similarly, tradition has also allowed any name
for argc
and argv
, and declaring argv
as char** argv
.
There's no tradition about defining main with a trailing return
type, however. I think that what was meant in §3.6.1 is that
all definitions of main
which have the same signature would be
allowed, but this is not what the actual words say.
Regardless: why would one want such obfuscation? C/C++ is not
Pascal, and what is natural in one language (like trailing
return types for functions) is obfuscation in another.
EDIT:
I've just downloaded a more recent draft (N3797), and it seems
like the wording has changed (and is now contradictory). The
first paragraph still says basically the same thing (but
includes addtiional wording for for lambdas): the auto
is
replaced "either by deduction from an initializer or by explicit
specification with a trailing-return-type." (And of course,
fucntions don't have initializers, so only the
trailing-return-type can apply.) Later paragraphs, however, do
speak about deduction from the return type, even though the
first paragraph requires the trailing return type (and thus
makes deduction superfluous).
auto
deduces the return type asvoid
. See stackoverflow.com/questions/17134975/… – 0x499602D2int
for case 3? – Tristan Brindleint
is the only legal return type why would anyone want to returnauto
for themain()
function? What would that buy you? – Void