Are function-local typedefs visible inside C++0x lambdas?
- by GMan - Save the Unicorns
I've run into a strange problem. The following simplified code reproduces the problem in MSVC 2010 Beta 2:
template <typename T>
struct dummy
{
static T foo(void) { return T(); }
};
int main(void)
{
typedef dummy<bool> dummy_type;
auto x = [](void){ bool b = dummy_type::foo(); };
// auto x = [](void){ bool b = dummy<bool>::foo(); }; // works
}
The typedef I created locally in the function doesn't seem to be visible in the lambda. If I replace the typedef with the actual type, it works as expected.
Here are some other test cases:
// crashes the compiler, credit to Tarydon
int main(void)
{
struct dummy {};
auto x = [](void){ dummy d; };
}
// works as expected
int main(void)
{
typedef int integer;
auto x = [](void){ integer i = 0; };
}
I don't have g++ 4.5 available to test it, right now. Is this some strange rule in C++0x, or just a bug in the compiler?
From the results above, I'm leaning towards bug. Though the crash is definitely a bug.
For now, I have filed two bug reports.
All code snippets above should compile. The error has to do with using the scope resolution on locally defined scopes. (Spotted by dvide.)
And the crash bug has to do with... who knows. :)
Update
According to the bug reports, they have both been fixed for the next release of Visual Studio 2010.