<div class="gmail_quote">On Tue, Jul 17, 2012 at 4:35 PM, Douglas Gregor <span dir="ltr"><<a href="mailto:dgregor@apple.com" target="_blank">dgregor@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
On Jul 16, 2012, at 3:28 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:<br>
<br>
> Hi,<br>
><br>
> As PR12917 notes, the mangling of lambads within templates is currently wrong -- not only do we not follow the ABI, we sometimes give the same mangled name to multiple lambdas. We use the templated declaration as the mangling context rather than the instantiation, and we don't take into account that the mangling number can depend on the number of template arguments if the template is variadic.<br>

><br>
> The attached patch fixes this by delaying the computation of the mangling information for a lambda in a dependent context until after instantiation.<br>
><br>
> Please review!<br>
<br>
</div></div>@@ -128,9 +126,12 @@<br>
       }<br>
     }<br>
<br>
+    unsigned ManglingNumber;<br>
     switch (Kind) {<br>
       case Normal:<br>
-        if (CurContext->isDependentContext() || isInInlineFunction(CurContext))<br>
+        if ((!ActiveTemplateInstantiations.empty() &&<br>
+             !(ContextDecl && isa<ParmVarDecl>(ContextDecl))) ||<br>
+            isInInlineFunction(CurContext))<br>
           ManglingNumber = Context.getLambdaManglingNumber(Method);<br>
         else<br>
           ManglingNumber = 0;<br>
@@ -140,7 +141,10 @@<br>
         break;<br>
<br>
       case StaticDataMember:<br>
-        if (!CurContext->isDependentContext()) {<br>
+        if (ActiveTemplateInstantiations.empty()) {<br>
+          // A mangling number for a lambda in a static data member of a class<br>
+          // template is only assigned when the data member is instantiated<br>
+          // from the template.<br>
           ManglingNumber = 0;<br>
           ContextDecl = 0;<br>
           break;<br>
<br>
I don't understand why we're checking ActiveTemplateInstantiations.empty() in these cases. That only tells us whether there's an instantiation occurring at any point; it isn't necessarily the right answer if we're instantiating, e.g., the declaration of a member template within a class template instantiation.</blockquote>
<div><br></div><div>I don't think that matters: we only care about the mangling details for fully-instantiated lambdas.</div></div>