<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJy1Fttu4jj0a8LLEVFwCpQHHloYNEizaqWttrtPlWM7iVsnjmynDH-_x04CKcusRrsdKYTY534_mebH9bOIyPJdANOVAMqMthYoWGdoXQiQ1rYCDqWoobWyLiBaJEwhaMpULL4LPIKu4VnWXB9sDHsHVojKgtNQUmRrHTVOcLDIHtkYAZlwB4H8VnESz4DWHGYkfGaC0dYKcKW0SNw0okZCmjthoG0KQ3lQgNzugVZQaH9CMc4c_V8mrWAO3oWxEjWyWtcRWcVRso2Su-69rxptHK2dx6-18-ahNIrncjBV1-rYC7djuxsj0EONVKhSKShHMchFf-C_k8Y6UMIButKW-hD4VrKWFVXgBAIZRQP3I4-3DRykKz_wYYbaMmZNE6X9Dbq5f7ojSWXNVMsFROkmb11rRJR-uQZk1nGpT0CJxldUomtu_Sc1BYvIBlhJTUTu_Pk9mt9H8y36DqLlfUcFaD6i50gVEdKHNJpvkA1BxCg94Y1IAGPPvQXp3aDhBpmgKjCcR7gfCEekjdEVRvZMe7r4gN9xRIO3A0JcCPfSC_Jqry7Ebc8qb69ZySVH85YYMh-NK8ae6C6DE94NK-Pyv0bwGsMnn4uHkDU-C33UlKzfQgGZtg5ZdKrOiNzjMxSokm9dVf1Im8ffZ961EVngb7nxaPPNo9FYcxXsUJrF87dvf_w2S7FSEzxkmELzzaUssoTpn-ESpqKSbopegKkG74wCPwenfLrQ3pdB3iBs-pCg6K6WEA_OVTUWH3uOA04HGfI7HC7S4Mfx-aoPApsPyPynozTqoc5HV_ZSxK8J1CAOHRaR3a4ZHIWHv5h_s08M0EjYKSXGURouR0o8cPiEgF0Nzj6Ho24BG0PX6_2Y0Tk8br5C1uLIclKpcPkvoTlo84ajsfDd89eH53Oc8dPZ--yNxJnPwlAtjW6LEsffMXgrEMNpKEtffhvvktOoz0LGe9ocu28gyilz3XDFB1PfySqUg4eh8A11OHQyJZ6OTXBzrs0A69rhizBGGw8S35lonJ_qJbU4uEOUdHPctTXz13iM4cmLqgSt-5Euayt5YPeyQdwvA4-H7BX3BM9W4mxnxnmlsGJfWxzPeF2JijXHPvAj0Zw6GlBLyYIzDkajveel5arqtRDcBiCOpQbbg9cbXzUuWC1z3mbtvTPenIaFpO8hBnwrdf3yVbdKNc4MHvunJ7xZvTIXmYwN0yd8WEEG_Tu_YYpYqI7Q1n6vwQ0pbFrU7zLUemVai_HEDWE24euUr9IVndDWldqsK-rca0GV0gd6nLRGrUvnmtDAyA6fAhtem8VoCx6Ueh_-puiPEAiyC4uXxY95enO7mJTrbJUvRJIsV6sbcktItlwQypf8Nhc3ZLbgZKJoJpRd-02FkFocut3Nz-f5dvL_NZBrkhCSzMiKzEg6X8SMk1WacpKLdLbIZ0l0kwjcolTs-cTaFBOzDiyztrAIVNI6ewZSa2WBmbDuVquJk06J9Tg6Pjt4G4ovFJv_wNZAcbUd7aAX-1QHuhiHfhu3tPLZwwe2wobmdWY6CQavg7V_A2sptyg>53486</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang-cl.exe producing crashing binary when using std::future when clang++.exe on same code produces working binary
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mattjgalloway
      </td>
    </tr>
</table>

<pre>
    We've come across a strange issue when using `clang-cl.exe` on Windows. It seems to have started somewhere between 9.0.1 and 12.0.1 because this happened after upgrading (I am going to try to bisect version soon).

Important to note is that the issue only happens when using precompiled headers too.

First let me show the minimal test case I've come up with.

crash.cpp:
```
#include <future>
#include <cstdio>
int main(int argc, char* argv[]) {
  printf("started\n");
  {
    std::future<int> future;
    {
      std::promise<int> promise;
      future = promise.get_future();
    }
  }
  printf("didn't crash\n");
}
```

pch.hpp:
```
#include <future>
```

Then we compile, link and run with `clang++.exe` like this:
```
PS1> & 'C:\Program Files\LLVM13.0.0\bin\clang++.exe' -Xclang -emit-pch -o pch.gch pch.hpp
PS1> & 'C:\Program Files\LLVM13.0.0\bin\clang++.exe' -include-pch pch.gch -O0-o crash.exe crash.cpp
PS1> .\crash.exe
started
didn't crash
```

However if we compile, link and run with `clang-cl.exe` then it crashes:
```
PS1> & 'C:\Program Files\LLVM13.0.0\bin\clang-cl.exe' /Fppch.gch /Yc /c pch.hpp
PS1> & 'C:\Program Files\LLVM13.0.0\bin\clang-cl.exe' -Xclang -include-pch -Xclang pch.gch /Od -o crash.exe crash.cpp
PS1> .\crash.exe
started
```

If you omit the use of PCH but still use `clang-cl.exe` then it works again:
```
PS1> & 'C:\Program Files\LLVM13.0.0\bin\clang-cl.exe' /Od -o crash.exe crash.cpp
PS1> .\crash.exe
started
didn't crash
```

When tracing through why the crash is happening, it seems to be coming from the fact that at runtime, the `CatchableType` for the `future_error` exception has no `copyFunction`. That means that inside `_CopyExceptionObject` in ucrt, we just `memcpy` the exception data, which is wrong because the `future_error` needs the proper copy constructor to run. It seems that the compiler emitting `nullptr` for `copyFunction` in the `clang-cl.exe`+PCH case is wrong. That's my understanding at least thus far!
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1Fttu4jj0a8LLERE4hZYHHloYNJVm1UpbbWefKsd2EreOHdlOGf5-j50EUpZZjVYdKYTY534_ueGH9bNIyPW7AGZqAZRZ4xxQcN5SXQqQzrUC9pXQ0DqpS0iWM6YQNGUqFT8EHsFoeJaam71L4d6DE6J24A1UFNk6T60XHByyRzZWQC78XiC_VTpL50A1hzmJn7lgtHUCfCUdEjeN0EhICy8stE1pKY8KkJt7oDWUJpxQjLeH8JdLJ5iHd2GdRI2cMTohqzSZbZPZbfe-rxtjPdU-4Gvjg3kojeK5Gkw1Wh164W5sd2MFeqiRClWqBOUoBrmYD_x30joPSnhAV7rK7CPfWmpZUwVeIJBRNPB-5PG2gb301Qc-zFJXpaxpkqy_QTf3T3ckmdRMtVxAkm2K1rdWJNmXS0D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