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.type.auto.deduct] Incorrect description of deduction for a variable with copy-initialization? #4088

Closed
languagelawyer opened this issue Jul 22, 2020 · 2 comments · Fixed by #4315
Assignees

Comments

@languagelawyer
Copy link
Contributor

languagelawyer commented Jul 22, 2020

[dcl.type.auto.deduct]/2 says:
"""
A type T containing a placeholder type, and a corresponding initializer E, are determined as follows:
­— for a variable declared with a type that contains a placeholder type, T is the declared type of the variable and E is the initializer. ...
"""

[dcl.type.auto.deduct]/4 says:
"""
If the placeholder-type-specifier is of the form type-constraintopt auto, the deduced type T replacing T is determined using the rules for template argument deduction.
Obtain P from T by replacing the occurrences of type-constraintopt auto either with a new invented type template parameter U, or ... [doesn't matter].
Deduce a value (!!!) for U using the rules of template argument deduction from a function call, where P is a function template parameter type and the corresponding argument is E.
...
[Example:

const auto &i = expr;

The type of i is the deduced type of the parameter u in the call f(expr) of the following invented function template:

template <class U> void f(const U& u);

— end example]
"""

There are several issues here (both in normative wording and the Example): the major one is that for a variable declared as const auto &i = expr;, the initializer is = expr, not expr. And one can't call a function with this initializer as an argument, like f(= expr). Probably, the paragraph should say that the initializer E is the default argument of an invented function template (and the type is deduces as if the function is called without argument)? Nah, the grammar for parameter-declaration doesn't allow initializer.

Also, is it ok that the Standard calls the deduced type "a value of a type parameter" and uses the instructing tone like Obtain P from T ... Deduce a value ....

@jensmaurer
Copy link
Member

I think "a value of a type parameter" is fine, and we also employ "obtain P from T" phrasing quite a bit in the template argument deduction area.

Properly removing the "=" from the initializer is an issue, though.

@xmh0511
Copy link
Contributor

xmh0511 commented Dec 7, 2020

So, how about this? decltype(auto) x2d(i); // decltype(x2d) is int

If the placeholder-type-specifier is of the form type-constraint opt decltype(auto), T shall be the placeholder alone. The type deduced for T is determined as described in [dcl.type.decltype], as though E had been the operand of the decltype.

That means E would be (i) which is the initializer, hence, decltype((i)) should be deduced to int&. I think we should preprocess the form of initializer in this description.

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

Successfully merging a pull request may close this issue.

3 participants