Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a better motivating example #2

Open
TBBle opened this issue May 13, 2017 · 1 comment
Open

Need a better motivating example #2

TBBle opened this issue May 13, 2017 · 1 comment

Comments

@TBBle
Copy link
Owner

TBBle commented May 13, 2017

The motivating example's pretty weak, and as noted in https://groups.google.com/a/isocpp.org/d/msg/std-proposals/eoU_uFtOOUA/I2i4D9MzCQAJ is actually flawed.

Quoting the whole email, although the typeid aside is already #1

The only reason I see personally, for why one might want to allow
this, is to support a default/value-initialized return object (such as
"return {};"). The ambiguity-resolution seems not to be so motivating,
as that can always be solved simply by putting extra parentheses
around the type (BTW a "void()" within sizeof, typeid etc does not
declare a function, but specifies a type. you may want to correct that
in the paper).

As such, you may want to change your example, by instead writing
"return {};". Because when you are already fine with repeating the
type name, you can easily write your return statement as "return
Return();". I see no problem with that, and advices such as "ES.23:
Prefer the {} initializer syntax" are based on personal taste and like
any rule-of-thumb, there may be exceptions. "Type()" is just as safe
as "Type{}". In fact, you can argue that "Type()" is yet safer because
"Type{}" allows the construction of unnamed references initialized by
temporaries, and therefore to hide this error:

int && f() { return decltype(f()){}; } // returns dangling reference

To clarify, I support your proposal, but I find it a bit poorly motivated.

@TBBle
Copy link
Owner Author

TBBle commented May 13, 2017

I need to find my notes from ACCU2017, I'm sure people suggested better motivations to me after the lightning talk, but I don't know if I wrote them down or not.

TBBle added a commit that referenced this issue May 13, 2017
As pointed out in #2, we're not actually declaring things here (that
would be ``void X()``). We are producing a type, so call it that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant