vendredi 5 juin 2015

What is the point of possibility to use compile-time characteristics of non-captured local variables in lambda?

I noticed that it is allowed to use compile-time characteristics of variables which was not captured in lambda e.g. call sizeof, decltype functions, for example:

#include <iostream>
void f ()
{
}

int main()
{
  int y = 13;
  auto x = []{ return sizeof (decltype (y));};
  std::cout << x () << '\n';
}

As both g++ and clang++ compile this program without errors I guess it is allowed by the standard.

It seems a bit misleading to me even though I can't think of any particular malicious case where it will lead to a mistake. But I wonder what are the actual use-cases of such possibility?

Aucun commentaire:

Enregistrer un commentaire