> Is there a reason why Clang prefers a trailing return type?
Using a trailing return type for main is just plain stupid.
There is no real type deduction with auto main() -> int
and the return type of main() is never going to be anything other than int.
Stick to the straightforward int main(); blithely ignore the noise that may be generated by the 'almost-always-auto' crowd.
I think the warning comes from Clang-Tidy, not Clang itself.
I have never used Clang-Tidy but I guess you can configure it somehow. You could probably disable the modernize-use-trailing-return-type warnings if you don't like them.
Using a trailing return type for main is just plain stupid.
There is no real type deduction with auto main() -> int
and the return type of main() is never going to be anything other than int.
Stick to the straightforward int main(); blithely ignore the noise that may be generated by the 'almost-always-auto' crowd.
I've never used auto with main() - always int, but just wondered if there was a good reason why Clang was reporting this. Seems not which is just what I thought.
MS VS doesn't generate any 'noise' about int main().
I guess the C++ standard allows an implementation to allow the trailing return type.
I honestly see little to no advantage of using a trailing return type with main.
If the standard committee ever formalized a trailing return type as part of the standard I still wouldn't use it. I like auto as a return type when it can reduce typing.
The mention about main in the C++ Core Guidelines is very specific, to tell the "compiler extension" devotees who insist void main is legit to shut the hell up.
If the standard committee ever formalized a trailing return type as part of the standard ...
I'm pretty sure the standard already allows a trailing return type for the main function as long as it's int.
The C++ Standard says:
An implementation shall allow both
– a function of () returning int and
– a function of (int, pointer to pointer to char) returning int
as the type of main
The standard may allow it, but it doesn't specify it in explicit terms except as some "implementation allowed" after-thought.
It is not a formal part of the standard at this time, period.
I meant that we can count on it being allowed. I.e. implementations has to allow it.
I think your interpretation makes sense for the old wording that was used before C++14.
The current wording, however, doesn't mention any specific syntax. If one keeps complaining about auto main() -> int not being explicitly mentioned one should do the same for int main() because it's no longer explicitly mentioned either.
MikeyBoy wrote:
where are C++ students going to get people to do their homework for them get help on programming, these days?
At least it had a couple of years ago. I don't hang out there any more. Too many interesting topics to respond and too much time wasted. That's why I came back here. ;)
where are C++ students going to get people to do their homework for them get help on programming, these days?
Is C++ still being taught much in colleges/universities? I've looked at a selection of Universities web sites and I only found one that mentioned C++ for a second year course. The vast majority covered Python/Java/Javascript