C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Fixing some initialization gotchas
From: Matthew Woehlke (mwoehlke.floss_at_[hidden])
Date: 2019-08-23 14:10:30


On 23/08/2019 13.44, Hyman Rosen wrote:
> You cannot teach a language in which auto x = { 1 };
> is fine but auto x { 1 }; is a terrible error that nevertheless compiles and
> silently does something you don't want.

...but the proposal is to make it *not* compile.

That said, my intuition says that's exactly the state we're already in.

When I look at `auto x = {1}`, the only logical explanation in my mind
is that the RHS is an initializer list, therefore `x` should deduce to
`std::initializer_list<int>`. When I see `auto x{1}`, I cannot provide a
logical explanation for what that is supposed to mean, therefore, that
it compiles at all is surprising, but that it does something I don't
want is not.

> When it comes time to write programs, no one is going to remember
> which is which.
I disagree. One of them looks sane. One does not. Therefore, it is easy
to remember that the one that looks sane, *is* sane, and the one that
looks like garbage is something I just shouldn't write.

> Having multiple constructs that appear to do something similar but
> have different behavior unapparent from the syntax is never going to
> be teachable.

You must have a different definition of "apparent" than I do. Anyway, I
still don't see the problem, since the proposal is to make one of them
ill-formed.

What confuses me is that Maciej and I are arguing that we *already have*
"multiple constructs that appear to do something similar but have
different behavior". I am confused why you seem in favor of that status quo?

-- 
Matthew

STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups