<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/61925>61925</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-cl] Failing to omit ATOMIC_VAR_INIT where it works in MSVC cl
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-cl
      </td>
    </tr>

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

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

<pre>
    CC @MaskRay @zmodem 

46262cab24312c71717ca70a9d0700481aa59152 broke building the OpenMP code with clang-cl, while it still works to build it with MSVC and in mingw mode.

46262cab24312c71717ca70a9d0700481aa59152 got rid of use of `ATOMIC_VAR_INIT` (which in itself expands to `{x}`) by just replacing it with `x` instead.

The issue can be observed in reduced form like this:
```c++
#include <atomic>

struct kmp_base_ticket_lock {
  std::atomic_int next_ticket;
};

static kmp_base_ticket_lock metadata_lock = {
  0
};
```
If the single initializer `0` in `metadata_lock` is replaced with `ATOMIC_VAR_INIT(0)` or plain `{0}`, the issue goes away.

With clang-cl, compiling this test snippet produces the following error:
```
atomic-init.cpp(8,3): error: copying member subobject of type 'std::atomic_int' (aka 'atomic<int>') invokes deleted constructor
  0
 ^
/home/martin/msvc2022/vc/tools/msvc/14.30.30705/include/atomic(2176,5): note: 'atomic' has been explicitly marked deleted here
    atomic(const atomic&) = delete;
    ^
1 error generated.
```
Same thing if building with libc++ instead of MS STL. The snippet compiles correctly with MSVC and with Clang in other modes than MSVC mode.


Note that this seems to happen while compiling in the default C++14 mode. If adding `-std:c++17` the error goes away.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVUtv2zoT_TX0ZhCDpl7WwovEqYEAX9oPTdC7DChybLGmSIGk4ri__mIk2WnSri5giA9zXjznDGWM5uAQN6y4Y8X9Qg6p9WHTxeRD_OkXjdfnzXYLLOePMh6_yzNNf3VeYweM3zN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