<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - libclang crash on lambda capture using deleted copy constructor"
   href="https://bugs.llvm.org/show_bug.cgi?id=46131">46131</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>libclang crash on lambda capture using deleted copy constructor
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>10.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>libclang
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>f.dennemont@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>klimek@google.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23554" name="attach_23554" title="The file that crashes libclang.">attachment 23554</a> <a href="attachment.cgi?id=23554&action=edit" title="The file that crashes libclang.">[details]</a></span>
The file that crashes libclang.

== Overview
When using libclang to parse the attached C++ file, it crashes. The C++ file
simply contains a lambda definition that captures by copy an object that has a
deleted copy constructor.

== Steps to Reproduce
1. Download the attached file.
2. Use libclang to parse that file. I use a simple code similar to this for the
parsing :
//---
ClangIndex = createIndex(false, false);
unsigned int options =
CXTranslationUnit_DetailedPreprocessingRecord|CXTranslationUnit_KeepGoing;
char const* const flags = ["-w", "-O0", "--std=c++17", "-c",
"--target=i686-pc-win32", "-fexceptions", "-fno-rtti", "-undef",
"-ferror-limit=100000", "-xc++", "-fshort-wchar",
"-Wno-dollar-in-identifier-extension"];
TU = parseTranslationUnit(ClangIndex, BuildOptions.szFileName, flags,
sizeof(flags)/sizeof(*Flags), Ocp.UnsavedFiles, Ocp.UnsavedFileCount, options);
CXCursor startCursor = getTranslationUnitCursor(TU);
visitChildren(startCursor, buildTree, &Datas);
//---

== Actual Results
The application crashed.

== Expected Results
No crash and libclang gives a diagnostic with a message similar to "call to a
deleted copy constructor".

== Build Date & Hardware
2020-05-29 on Windows 7.

== libclang version : 10 (on that commit :
<a href="https://github.com/llvm/llvm-project/commit/92d5c1be9ee93850c0a8903f05f36a23ee835dc2">https://github.com/llvm/llvm-project/commit/92d5c1be9ee93850c0a8903f05f36a23ee835dc2</a>)


== Additional Information
I fixed the bug locally by simply ignoring a null pointer, like this :
in clang/tools/libclang/CIndex.cpp line 3174 :
        // Visit init captures
        for (auto InitExpr : E->capture_inits()) {
-          if (Visit(InitExpr))
+          if (InitExpr && Visit(InitExpr))
            return true;
        }</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>