According to the C++23 standard, what is the output of this program?
#include <iostream>
int main() {
int a = 0;
decltype((a)) b = a;
b++;
std::cout << a << b;
}decltype((a)) is not the same as decltype(a).
11
According to §[dcl.type.decltype]¶1 in the standard:
For an expression
E, the type denoted bydecltype(E)is defined as follows:— if
Eis an unparenthesized id-expression naming a structured binding (§[dcl.struct.bind]),decltype(E)is the referenced type as given in the specification of the structured binding declaration;— otherwise, if
Eis an unparenthesized id-expression naming a non-type template-parameter (§[temp.param]),decltype(E)is the type of the template-parameter after performing any necessary type deduction (§[dcl.spec.auto], §[dcl.type.class.deduct]);— otherwise, if
Eis an unparenthesized id-expression or an unparenthesized class member access (§[expr.ref]),decltype(E)is the type of the entity named byE. If there is no such entity, the program is ill-formed;— otherwise, if
Eis an xvalue,decltype(E)isT&&, whereTis the type ofE;— otherwise, if
Eis an lvalue,decltype(E)isT&, whereTis the type ofE;— otherwise,
decltype(E)is the type ofE.
Because a is encapsulated in parentheses, it doesn't qualify for the first three cases, it is treated as an lvalue, therefore b's type is int&, not int.