As I understood in C++11 decltype(expression) is used to deduce the exact same type of the given expression. But when the expression is put into parentheses its
From one of the authors of the decltype proposal, J. Jarvi:
It’s been a while, but here’s what I (think I) remember:
Two separate keywords for differentiating these two kinds of semantics was never considered. (Introducing new keywords is not done lightly).
As to the change of the semantics of
decltype((x)), discussion in the core working group converged to treating(x)as an expression, rather than an identifier, which perhaps is more “internally consistent” with the language rules.People were aware that this could potentially be confusing in some cases, but the consensus (while perhaps not everyone’s preference) was eventually to be consistent with the standard’s prior definition of what is an identifier and what is an expression.
The example you link to [this question's example] is indeed surprising. At the time, deducing a function’s return type from its return expression using
decltype(auto)was not yet part of the language, so I don’t think this particular use case was on anyone’s radar.