Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Explicitly deduced return type (like "auto foo() -> auto"), is that valid?

20 views
Skip to first unread message

Alf P. Steinbach

unread,
Aug 20, 2019, 10:59:56 PM8/20/19
to
Specifically, is

auto foo() -> auto { return 42; }

auto main() -> int
{
return foo();
}

... valid?

I'd guess that it's not valid as C++11, but possibly valid as C++14 or
later.

It compiles with Visual C++ 2019 and g++ 9.2.


Cheers!,

- Alf

Tim Rentsch

unread,
Aug 22, 2019, 8:05:19 AM8/22/19
to
"Alf P. Steinbach" <alf.p.stein...@gmail.com> writes:

> Specifically, is
>
> auto foo() -> auto { return 42; }
>
> auto main() -> int
> {
> return foo();
> }
>
> ... valid?
>
> I'd guess that it's not valid as C++11, but possibly valid as
> C++14 or later.

fwiw, g++ and clang accept it without complaint under -std=c++14
and -std=c++17, but give a diagnostic under -std=c++11. That
result holds both with and without a -pedantic option.
0 new messages