C++ Logo

std-discussion

Advanced search

Does the wording about the rule of deduction for type placeholder for a variable declaration exist a defect

From: jim x <xmh970252187_at_[hidden]>
Date: Tue, 1 Sep 2020 15:27:43 +0800
Hi, everyone.

After reading the rule of [dcl.type.auto.deduct] section. I wonder Does
such the following rule exist a vague, that is:
[dcl.type.auto.deduct] <https://eel.is/c++draft/dcl.type.auto.deduct#2.2>
> 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. If the
initialization is direct-list-initialization, the initializer shall be a
braced-init-list containing only a single assignment-expression and E is
the assignment-expression;

````
auto v0 = 0; // #1
auto v1(0); //#2
````
Please consider the above two declarations, According to the above rule, I
think, the initializer of the declaration declared at #1 is `= 0`, and the
initializer of the declaration declared at #2 is "(0)", because of the
definition of "initializer",

initializer:
>brace-or-equal-initializer
>( expression-list )
Where brace-or-equal-initializer is,
brace-or-equal-initializer:
= initializer-clause
braced-init-list

>If the placeholder-type-specifier is of the form type-constraint<opt>
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-constraint<opt> auto either with a new invented type template
parameter U or, if the initialization is copy-list-initialization, with
std::initializer_­list<U>. 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. If the deduction fails,
the declaration is ill-formed. Otherwise, T′ is obtained by substituting
the deduced U into P.

So, how could the initializer such as `= 0`, `(0)` be as an argument? Since
there's an adjustment for the case where the initialization is
"direct-list-initialization", why does the rule not make a adjustment to
cover these cases where the initializer is the form of = initializer-clause
or (expression-list) ?

I don't think when `E` is form of `= initializer-clause` or
`(expression-list) ` used as argument is the intent of the rule
[dcl.type.auto.deduct#2.2]

Maybe change [dcl.type.auto.deduct#2.2] to:
for a variable declared with a type that contains a placeholder type, T is
the declared type of the variable and If the initialization is
direct-list-initialization, the initializer shall be a braced-init-list
containing only a single assignment-expression and E is the
assignment-expression; if the initializer has the form `=
initializer-clause` or `(expression-list) `, then E is `initializer-clause`
or `expression-list` respectively.

I think Only after applying these adjustments for `E` is such the `E` that
participates in type placeholder deduction.

Received on 2020-09-01 02:31:24