Skip to content

Commit 4ee4313

Browse files
chrisncyuxuanchen1997
authored andcommitted
[clang] Define ATOMIC_FLAG_INIT correctly for C++. (#97534)
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250653
1 parent 5031861 commit 4ee4313

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

clang/docs/ReleaseNotes.rst

+3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ Improvements to Coverage Mapping
133133
Bug Fixes in This Version
134134
-------------------------
135135

136+
- Fixed the definition of ``ATOMIC_FLAG_INIT`` in ``<stdatomic.h>`` so it can
137+
be used in C++.
138+
136139
Bug Fixes to Compiler Builtins
137140
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
138141

clang/lib/Headers/stdatomic.h

+4
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@ typedef _Atomic(uintmax_t) atomic_uintmax_t;
172172

173173
typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;
174174

175+
#ifdef __cplusplus
176+
#define ATOMIC_FLAG_INIT {false}
177+
#else
175178
#define ATOMIC_FLAG_INIT { 0 }
179+
#endif
176180

177181
/* These should be provided by the libc implementation. */
178182
#ifdef __cplusplus

clang/test/Headers/stdatomic.c

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// RUN: %clang_cc1 -std=c11 -E %s | FileCheck %s
22
// RUN: %clang_cc1 -std=c11 -fms-compatibility -E %s | FileCheck %s
3+
// RUN: %clang_cc1 -std=c11 %s -verify
4+
// RUN: %clang_cc1 -x c++ -std=c++11 %s -verify
5+
// expected-no-diagnostics
36
#include <stdatomic.h>
47

58
int bool_lock_free = ATOMIC_BOOL_LOCK_FREE;
@@ -31,3 +34,5 @@ int llong_lock_free = ATOMIC_LLONG_LOCK_FREE;
3134

3235
int pointer_lock_free = ATOMIC_POINTER_LOCK_FREE;
3336
// CHECK: pointer_lock_free = {{ *[012] *;}}
37+
38+
atomic_flag f = ATOMIC_FLAG_INIT;

0 commit comments

Comments
 (0)