[LLVMbugs] [Bug 15906] New: incorrect warning about uninitialized variable in lamba function argument

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri May 3 11:36:32 PDT 2013


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: unassignedclangbugs at nondot.org
          Reporter: andreas.boerner at w84u.org
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130503/22b51148/attachment.html>


More information about the llvm-bugs mailing list