forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc++] Don't implement <stdatomic.h> before C++23
llvm#95498 implemented a libc++ extension where <stdatomic.h> would forward to <atomic> even before C++23. Unfortunately, this was found to be a breaking change (with fairly widespread impact) since that changes whether _Atomic(T) is a C style atomic or std::atomic<T>. In principle, this can even be an ABI break. We generally don't implement extensions in libc++ because they cause so many problems, and that extension had been accepted because it was deemed pretty small and only a quality of life improvement. Since it has widespread impact on valid C++20 (and before) code, this patch removes the extension before we ship it in any public release.
- Loading branch information
Showing
6 changed files
with
86 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
libcxx/test/libcxx/atomics/atomics.syn/incompatible_with_stdatomic.verify.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: no-threads | ||
// REQUIRES: c++03 || c++11 || c++14 || c++17 || c++20 | ||
|
||
// This test ensures that we issue a reasonable diagnostic when including <atomic> after | ||
// <stdatomic.h> has been included. Before C++23, this otherwise leads to obscure errors | ||
// because <atomic> may try to redefine things defined by <stdatomic.h>. | ||
|
||
// Ignore additional weird errors that happen when the two headers are mixed. | ||
// ADDITIONAL_COMPILE_FLAGS: -Xclang -verify-ignore-unexpected=error -Xclang -verify-ignore-unexpected=warning | ||
|
||
#include <stdatomic.h> | ||
#include <atomic> | ||
|
||
// expected-error@*:* {{<atomic> is incompatible with <stdatomic.h> before C++23.}} |
24 changes: 24 additions & 0 deletions
24
libcxx/test/libcxx/atomics/stdatomic.h.syn/dont_hijack_header.compile.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: no-threads | ||
|
||
// This test ensures that we don't hijack the <stdatomic.h> header (e.g. by providing | ||
// an empty header) even when compiling before C++23, since some users were using the | ||
// Clang or platform provided header before libc++ added its own. | ||
|
||
// On GCC, the compiler-provided <stdatomic.h> is not C++ friendly, so including <stdatomic.h> | ||
// doesn't work at all if we don't use the <stdatomic.h> provided by libc++ in C++23 and above. | ||
// XFAIL: (c++11 || c++14 || c++17 || c++20) && gcc | ||
|
||
#include <stdatomic.h> | ||
|
||
void f() { | ||
atomic_int i; // just make sure the header isn't empty | ||
(void)i; | ||
} |
25 changes: 25 additions & 0 deletions
25
libcxx/test/libcxx/atomics/stdatomic.h.syn/dont_hijack_header.cxx23.compile.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: no-threads | ||
// XFAIL: FROZEN-CXX03-HEADERS-FIXME | ||
|
||
// This test verifies that <stdatomic.h> DOES NOT redirect to <atomic> before C++23, | ||
// since doing so is a breaking change. Several things can break when that happens, | ||
// because the type of _Atomic(T) changes from _Atomic(T) to std::atomic<T>. | ||
// | ||
// For example, redeclarations can become invalid depending on whether they | ||
// have been declared with <stdatomic.h> in scope or not. | ||
|
||
// REQUIRES: c++03 || c++11 || c++14 || c++17 || c++20 | ||
|
||
#include <atomic> | ||
#include <stdatomic.h> | ||
#include <type_traits> | ||
|
||
static_assert(!std::is_same<_Atomic(int), std::atomic<int> >::value, ""); |