http://llvm.org/bugs/show_bug.cgi?id=15906

            Bug ID: 15906
           Summary: incorrect warning about uninitialized variable in
                    lamba function argument
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified

Created attachment 10464
  --> http://llvm.org/bugs/attachment.cgi?id=10464&action=edit
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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to