4

Is the following code valid according to (any) C++ ISO standards?

#include <functional>

auto a() {
    struct Foo {
    };
    return []() {return Foo{}; };
}

int main()
{
    auto l = a()();
    decltype(l) ll;
    //Foo f; //error: unknown type name 'Foo'
    return 0;
}

The compilers (Visual studio 2015, latest Clang and latest GCC) accept this but it seems weird that decltype should give me access to Foo.

Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
DDaniel
  • 285
  • 1
  • 7

1 Answers1

5

Yes.

It is actually the name of the type that is scoped, not the type itself.

You're not using its name, so everything is fine.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055