<html>
    <head>
      <base href="http://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 --- - incorrect warning about uninitialized variable in lamba function argument"
   href="http://llvm.org/bugs/show_bug.cgi?id=15906">15906</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>incorrect warning about uninitialized variable in lamba function argument
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </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>andreas.boerner@w84u.org
          </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>Created <span class=""><a href="attachment.cgi?id=10464" name="attach_10464" title="cc file that contains the bug">attachment 10464</a> <a href="attachment.cgi?id=10464&action=edit" title="cc file that contains the bug">[details]</a></span>
cc file that contains the bug

the following program generates an invalid warning:

#include <iostream>
#include <functional>

struct A {
      A(std::function< void (void)> lf) : m_f(lf) {};
      void exec() { m_f(); };

      std::function<void(void)> m_f;
      bool m_b = false;
};

namespace {
   A x([](){ x.m_b = true; std::cout << "x.m_b: " << x.m_b << std::endl; });
}

int main()
{
   x.exec();
   return 0;
}




the warning is:

clang++ -std=gnu++11 -Wall -Weffc++ -D__STRICT_ANSI__ -I . -O0 -ggdb -o t_clang
main.cc
main.cc:13:54: warning: variable 'x' is uninitialized when used within its own
initialization [-Wuninitialized]
   A x([](){ x.m_b = true; std::cout << "x.m_b: " << x.m_b << std::endl; });
     ~                                               ^
1 warning generated.


The warning in invalid, because the lambda is not executed inside the A c'tor,
but outside, at x.exec()! It can never be otherwise!


$ clang++ --version
clang version 3.3 (trunk 178622)
Target: x86_64-unknown-linux-gnu
Thread model: posix


Makefile:

all: gcc clang

gcc:
    g++ -std=gnu++11 -Wall -Weffc++ -I . -O0 -ggdb -o t_gcc main.cc
    @ls -sh t_gcc
clang:
    clang++ -std=gnu++11 -Wall -Weffc++ -D__STRICT_ANSI__ -I . -O0 -ggdb -o
t_clang main.cc
    @ls -sh t_clang

clean:
    @rm -f t_gcc
    @rm -f t_clang</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>