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

             Bug #: 14921
           Summary: recursive lambda warns "uninitialized within its own
                    definition"
           Product: clang
           Version: 3.2
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]
    Classification: Unclassified


Compiling the following code with "clang++ -std=c++11 -Wuninitialized" results
in the following warning:

cpp1.cpp:9:7: warning: variable 'recur' is uninitialized when used within its
own initialization [-Wuninitialized]
      recur(val - 1);
      ^~~~~
1 warning generated.

This is with clang 3.2 release. I think it has not happened with 3.1, though I
cannot test that at the moment as I don't have 3.1 installed anymore.

The code executes just fine and prints out the expected ("210").

Compiling with "-O2" yields code that runs just as well.

Code:

#include <functional>
#include <iostream>

int
main() {
  std::function<void(unsigned int)> recur = [&recur](unsigned int val) {
    std::cout << val;
    if (val)
      recur(val - 1);
  };

  recur(2);
  std::cout << std::endl;

  return 0;
}

Splitting the assignment into declaration and assignment makes the warning go
away:

  std::function<void(unsigned int)> recur;
  recur = [&recur](unsigned int val) {

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- 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