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

    <tr>
        <th>Summary</th>
        <td>
            Regression: stdatomic.h should not forward to MSVC's incompatible version in C11
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    This is a regression from e0c3142af075e2ef89395dbed5939071345eb622. (@compnerd FYI)

Originally, Clang's `<stdatomic.h>` would forward to the system's copy if `__has_include_next(<stdatomic.h>)`. This meant that, among other things, clang-cl would still provide C11 atomics even though MSVC headers didn't provide it. (This is nice and consistent with clang-cl defining `__STDC_VERSION__ >= 201112L` without `__STDC_NO_ATOMICS__`.)

Then C++23 decided to add `<stdatomic.h>` to improve C11 compatibility. Newer MSVC now provides stdatomic.h, but it only works in C++23. In C, it fails with:

> #error <stdatomic.h> is not yet supported when compiling as C, but this is planned for a future release.

Ironically, this C11-compatibility improvement in C++23 made clang-cl less C11-compatible. ðŸ˜„ So, 1ad7de9e92bc2977698e5f6d6493202b50c912d5 made clang's `<stdatomic.h>` skip the system's  if `defined(_MSC_VER)`.

Then ba49d39b20cc5358da28af2ac82bd336028780bc defined the workaround to only skip on MSVC and C. MSVC and C++ would still forward to MSVC's C++23 header. That's still fine and C11-compatible.

However, e0c3142af075e2ef89395dbed5939071345eb622 regressed this. It now targets the workaround to only MSVC and pre-C++23. It seems to have inadvertently dropped the workaround in C11, despite the comment still referencing C. This now breaks clang-cl in C11 mode. clang-cl still defines `__STDC_VERSION__ >= 201112L` without `__STDC_NO_ATOMICS__`, yet `#include <stdatomic.h>` doesn't work.

I think the condition should have been `!(defined(_MSC_VER) && (!defined(__cplusplus) || __cplusplus < 202002L)`
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVk1v2zgQ_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