[clang] [clang] Define ATOMIC_FLAG_INIT correctly for C++. (PR #97534)

Chris Copeland via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 3 00:30:41 PDT 2024


chrisnc wrote:

Without this change, trying to use `ATOMIC_FLAG_INIT` in a constant initialization context yields the following:

https://godbolt.org/z/sTvMs5a95

```
<source>:3:17: error: non-constant-expression cannot be narrowed from type 'int' to 'atomic_bool' (aka '_Atomic(bool)') in initializer list [-Wc++11-narrowing]
    3 | atomic_flag x = ATOMIC_FLAG_INIT;
      |                 ^~~~~~~~~~~~~~~~
/opt/compiler-explorer/clang-trunk-20240703/lib/clang/19/include/stdatomic.h:169:28: note: expanded from macro 'ATOMIC_FLAG_INIT'
  169 | #define ATOMIC_FLAG_INIT { 0 }
      |                            ^
<source>:3:17: note: insert an explicit cast to silence this issue
    3 | atomic_flag x = ATOMIC_FLAG_INIT;
      |                 ^~~~~~~~~~~~~~~~
/opt/compiler-explorer/clang-trunk-20240703/lib/clang/19/include/stdatomic.h:169:28: note: expanded from macro 'ATOMIC_FLAG_INIT'
  169 | #define ATOMIC_FLAG_INIT { 0 }
      |                            ^
1 error generated.
Compiler returned: 1
```

https://github.com/llvm/llvm-project/pull/97534


More information about the cfe-commits mailing list