Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload