Index: clang/lib/Headers/stdatomic.h =================================================================== --- clang/lib/Headers/stdatomic.h +++ clang/lib/Headers/stdatomic.h @@ -40,6 +40,10 @@ /* 7.17.2 Initialization */ #define ATOMIC_VAR_INIT(value) (value) +#if __STDC_VERSION__ >= 201710L || __cplusplus >= 202002L +/* ATOMIC_VAR_INIT was deprecated in C17 and C++20. */ +#pragma clang deprecated(ATOMIC_VAR_INIT) +#endif #define atomic_init __c11_atomic_init /* 7.17.3 Order and consistency */ @@ -149,6 +153,10 @@ typedef struct atomic_flag { atomic_bool _Value; } atomic_flag; #define ATOMIC_FLAG_INIT { 0 } +#if __cplusplus >= 202002L +/* ATOMIC_FLAG_INIT was deprecated in C++20 but is not deprecated in C. */ +#pragma clang deprecated(ATOMIC_FLAG_INIT) +#endif /* These should be provided by the libc implementation. */ #ifdef __cplusplus Index: clang/test/Headers/stdatomic-deprecations.c =================================================================== --- /dev/null +++ clang/test/Headers/stdatomic-deprecations.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c11 %s -verify=okay +// RUN: %clang_cc1 -fsyntax-only -std=c17 %s -verify +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -x c++ %s -verify=okay +// RUN: %clang_cc1 -fsyntax-only -std=c++20 -x c++ %s -verify=cxx,expected + +// okay-no-diagnostics + +#include + +void func(void) { + (void)ATOMIC_VAR_INIT(12); // expected-warning {{macro 'ATOMIC_VAR_INIT' has been marked as deprecated}} \ + // expected-note@stdatomic.h:* {{macro marked 'deprecated' here}} + #if defined(ATOMIC_FLAG_INIT) // cxx-warning {{macro 'ATOMIC_FLAG_INIT' has been marked as deprecated}} \ + // cxx-note@stdatomic.h:* {{macro marked 'deprecated' here}} + #endif +}