lundi 24 février 2020

C++ decltype and parentheses - why?

The subject was discussed before, but this is not a duplicate.

When someone asks about the difference between decltype(a) and decltype((a)), the usual answer is - a is a variable, (a) is an expression. I find this answer unsatisfying.

First, a is an expression as well. The options for a primary expression include, among others -

  • ( expression )
  • id-expression

More importantly, the phrasing for decltype considers parentheses very, very explicitly:

For an expression e, the type denoted by decltype(e) is defined as follows:
(1.1)  if e is an unparenthesized id-expression naming a structured binding, ...
(1.2)  otherwise, if e is an unparenthesized id-expression naming a non-type template-parameter, ...
(1.3)  otherwise, if e is an unparenthesized id-expression or an unparenthesized class member access, ...
(1.4)  otherwise, ...

So the question remains. Why are parentheses treated differently? Is anyone familiar with technical papers or committee discussions behind it? The explicit consideration for parentheses leads to think this is not an oversight, so there must be a technical reason I'm missing.

Aucun commentaire:

Enregistrer un commentaire