With regard to holding the placeholder type
I hereby refer strictly to the C ++ project ( N4659 ). In the following example
int&& f();
auto x5a = f(); // decltype(x5a) is int
I'm not sure why the inferred type int
insteadint&&
. Scott Meyers said in his book that
..., the reference to the initialization expression is ignored.
However, I have not been able to find any paragraph in the above project that provides an assertion. Here are the steps taken to infer the type:
-
According to clause 10.1.7.4.1 [dcl.type.auto.deduct] clause 2,
A type
T
containing a placeholder type and a corresponding initializere
is defined as follows:- ...
- for a variable declared with a type that contains a placeholder type,
T
is the declared type of the variable, ande
is an initializer ...
Therefore,
T
-auto
, ae
-f()
. -
According to clause 10.1.7.4.1 [dcl.type.auto.deduct],
If the placeholder is an automatic type specifier, ... Get
P
fromT
, replacing the occurrences auto with either the newly invented template type,U
or, ... Derive the value forU
"using the rules of template argument deduction from a function call , whereP
is the type of the function template parameter, and the corresponding argumente
...Therefore,
P
-U
, aA
-int&&
. -
According to clause 17.8.2.1 [temp.deduct.call],
If
P
not a reference type:- If
A
is an array type, ... - If
A
is a function type, ... - If
A
is a cv-qualified type, ...
Although
P = U
not really a reference type, itA = int&&
remains so because the above three cases do not apply toA
. - If
These are the only paragraphs I have found that I think are relevant to this particular case. In conclusion, U = int&&
and all T
as well int&&
.
I'm definitely missing something here and I'm not sure what it is. If you are kind enough to answer this question, would you limit yourself to formal wording (with a C ++ draft or standard)?
source to share
No one has answered this question yet
Check out similar questions: