[PATCH] D11555: [libcxx] Allow use of <atomic> in C++03. Try 3.

Eric Fiselier eric at efcs.ca
Tue Jul 28 00:04:24 PDT 2015


EricWF created this revision.
EricWF added reviewers: mclow.lists, chandlerc, jroelofs.
EricWF added a subscriber: cfe-commits.

After putting this question up on cfe-dev I have decided that it would be best to allow the use of `<atomic>` in C++03. Although static initialization is a concern the syntax required to get it is C++11 only. Meaning that C++11 constant static initialization cannot silently break in C++03, it will always cause a syntax error. Furthermore `ATOMIC_VAR_INIT` and `ATOMIC_FLAG_INIT` remain defined in C++03 even though they cannot be used because C++03 usages will cause better error messages.

The main change in this patch is to replace `__has_feature(cxx_atomic)`, which only returns true when C++ >= 11, to `__has_extension(c_atomic)` which returns true whenever clang supports the required atomic builtins.


This patch adds the following macros:
* `_LIBCPP_HAS_C_ATOMIC_IMP`      - Defined on clang versions which provide the C `_Atomic` keyword.
* `_LIBCPP_HAS_GCC_ATOMIC_IMP` - Defined on GCC > 4.7. We must use the fallback atomic implementation.
* `_LIBCPP_HAS_NO_ATOMIC_HEADER` - Defined when it is not safe to include `<atomic>`.

`_LIBCPP_HAS_C_ATOMIC_IMP` and `_LIBCPP_HAS_GCC_ATOMIC_IMP` are mutually exclusive, only one should be defined. If neither is defined then `<atomic>` is not implemented and including `<atomic>` will issue an error.



http://reviews.llvm.org/D11555

Files:
  include/__config
  include/atomic
  include/ios
  include/memory
  src/ios.cpp
  src/memory.cpp
  test/std/atomics/atomics.flag/atomic_flag_clear.pass.cpp
  test/std/atomics/atomics.flag/atomic_flag_clear_explicit.pass.cpp
  test/std/atomics/atomics.flag/clear.pass.cpp
  test/std/atomics/atomics.flag/init.pass.cpp
  test/std/atomics/atomics.flag/init03.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_strong.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_strong_explicit.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_weak.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_compare_exchange_weak_explicit.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_exchange.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_exchange_explicit.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_and_explicit.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_or.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_or_explicit.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_xor.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_xor_explicit.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_helpers.h
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_init.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_is_lock_free.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_load.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_load_explicit.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_store.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_store_explicit.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_var_init.pass.cpp
  test/std/atomics/atomics.types.operations/atomics.types.operations.req/ctor.pass.cpp
  test/support/test_macros.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11555.30788.patch
Type: text/x-patch
Size: 43038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150728/057fcfda/attachment.bin>


More information about the cfe-commits mailing list