<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW " title="NEW --- - Corrupted member initialization via initialization list when in a lambda nested in a templated function" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24077&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=HuKrSx4KpQsTrlv2vU7UD3BwOVwdmonZwZrwcdomthY&s=6j59LbN4CMIlhUCrb1neLhInQry2FVGw4TeMlKKa9-Q&e=">24077</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Corrupted member initialization via initialization list when in a lambda nested in a templated function
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.6
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++11
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>avasilev@gmx.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>A simple class member initialization from a ctor parameter in a ctor
initialization list results in an incorrect value for that member. Doing the
initialization in the constructor body works. Tested with clang 3.4, 3.5 and
3.6 (3.6 installed from this site) on Ubuntu.

Code:

#include <stdio.h>
#include <functional>
typedef void(*cfunc_t)(void*);
template <class F>
void test(F&& f)
{
    struct Msg
    {
        F func;
        cfunc_t cfunc;
        Msg(cfunc_t aCfunc, F&& aFunc)
        :cfunc(aCfunc), func(std::forward<F>(aFunc)){}
    };
    Msg msg([](void* ptr)
    {
        struct Test
        {
            Msg* mMsg;
            Test(Msg* aMsg): mMsg(aMsg) // <=== BUG: mMsg has a corrupted
value!
            { printf("aMsg = %p, mMsg = %p\n", aMsg, this->mMsg);}
        };
        Test t(static_cast<Msg*>(ptr));
    }, std::forward<F>(f));

    msg.cfunc(nullptr);
}
int main()
{
    test([](){});
}

===================
Output:

aMsg = (nil), mMsg = 0x4006b5</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>