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

[dcl.spec.auto] is disorganized and hard to follow #437

Closed
zygoloid opened this issue Jan 27, 2015 · 2 comments
Closed

[dcl.spec.auto] is disorganized and hard to follow #437

zygoloid opened this issue Jan 27, 2015 · 2 comments

Comments

@zygoloid
Copy link
Member

auto means a bunch of different things. [dcl.spec.auto] does a bad job of listing those things and explaining how they work. Some specific grievances:

p1 acts as an introduction / summary, but also mixes in a definition of "placeholder type". This leaves confusion over whether the auto introducing a trailing-return-type or generic lambda is a placeholder type. It also introduces cases in a different order from the order in which they're disposed in the following paragraphs.

p2 seems very confused about what it's specifying. It talks about appearing "with a function declarator", which is not meaningful -- which contexts are sufficiently "with" to be covered here? It talks about a type-specifier-seq which can't appear in or near a function declarator, except in a conversion-function-id, which is covered separately. It talks about a decl-specifier-seq, and it's unclear whether it means the decl-specifier-seq of the declaration (which is not part of the declarator, but perhaps this is what "with" meant) or of parameter declarations. It talks about placeholder types in the conversion-function-id or trailing-return-type, which for symmetry with the other cases should better talk about the type-specifier-seq of the conversion-type-id and the trailing-type-specifier-seq.

p2 says "... in any context where such a declarator is valid", which is a lie. Placeholder types are not allowed in _type-id_s, for instance.

p2 says "Otherwise, the function declarator shall declare a function." That's wrong, it disallows

auto (*p)() = &f;

p2 presumably should, but does not, require that auto be the only type in the decl-specifier-seq when we have a trailing-return-type. That's way over in 8.3.5, but should at least have a note here.

p3 seems OK by itself, but would benefit from saying "the lambda is a generic lambda (5.1.2) and the auto type-specifier is replaced by the name of an invented template parameter".

p4 doesn't make it clear under what circumstances a variable is "declared using auto or decltype(auto)"; we should actually talk about the cases where these things appear in the decl-specifier-seq up front, rather than sinking that into the second sentence.

Splitting p4 and p5 up makes no sense at all. p4 says "Here's when we do this deduction thing." p5 says "Oh, also here are some more cases we forgot before." We should combine all these cases into a single list of all the relevant places where a variable can be declared with a placeholder type in its decl-specifier-seq or type-specifier-seq. p5 also sneaks in the new-type-id case, which has no place in a list of "declaring a variable" cases.

p6 is somewhat randomly placed; it belongs in p1.

p7 is impenetrably long. It needs to be split up into different paragraphs more clearly explaining the process here. It also fails to address the new-type-id case (we weirdly put that specification elsewhere).

p7 starts introducing rules like "If the initialization is direct-list-initialization then the braced-init-list shall contain only a single initializer-clause L." We already had a rule like this way back in p4; does it really make sense to split them up like this?

We then have "If the placeholder type is the decltype(auto) ..." paragraph that looks like it should have a separate number, rather than being rolled into p7. As noted in another issue, we'd benefit from defining a term like "the declared type of an expression e" here. This wording also fails to explicitly say what happens when the initializer is a braced-init-list (reading between the lines, or consulting the example, you can tell it should be ill-formed, but we don't usually say "as if ").

p8 starts talking about "the init-declarator-list" without establishing a context where we necessarily have one.

p9 onwards starts talking about deduced return types, which is weird; p2 talked about them, then we had this big intermission when we talked about variables, but now we're back to functions again.

@jensmaurer
Copy link
Member

I agree 7.1.7.4 needs a rebrush. However, I am uncomfortable doing that editorially, since a lot of text will be modified in a non-trivial fashion.
Richard, are you ok with opening a core issue for that?

@zygoloid
Copy link
Member Author

Recent auto / placeholder type work has improved this substantially.

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

2 participants