[LLVMbugs] [Bug 14921] New: recursive lambda warns "uninitialized within its own definition"

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jan 11 09:16:58 PST 2013


             Bug #: 14921
           Summary: recursive lambda warns "uninitialized within its own
           Product: clang
           Version: 3.2
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: moritz at bunkus.org
                CC: llvmbugs at cs.uiuc.edu
    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.


#include <functional>
#include <iostream>

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

  std::cout << std::endl;

  return 0;

Splitting the assignment into declaration and assignment makes the warning go

  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.

More information about the llvm-bugs mailing list