Page MenuHomePhabricator

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

Authored by EricWF on Jul 28 2015, 12:04 AM.

Details

Summary

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.

Diff Detail

Event Timeline

EricWF updated this revision to Diff 30788.Jul 28 2015, 12:04 AM
EricWF retitled this revision from to [libcxx] Allow use of <atomic> in C++03. Try 3..
EricWF updated this object.
EricWF added reviewers: mclow.lists, chandlerc, jroelofs.
EricWF added a subscriber: cfe-commits.
mclow.lists edited edge metadata.Jul 29 2015, 9:35 AM

In general, this is looking quite good.

include/ios
373

Do you need to address this TODO before committing? (and the one in <memory> ?)

test/std/atomics/atomics.types.operations/atomics.types.operations.req/atomic_helpers.h
42

Is there a way to do this w/o exposing the name test here?
Maybe a type list and then apply-ing to to each member of the type list?

EricWF updated this revision to Diff 30985.Jul 29 2015, 9:36 PM
EricWF updated this object.
EricWF edited edge metadata.
  • Address review comments.
EricWF updated this revision to Diff 30987.Jul 29 2015, 10:36 PM

That last patch had a bunch of junk in it. My mistake. This patch is better.

EricWF added inline comments.Jul 30 2015, 8:56 AM
include/ios
373

Do you need to address this TODO before committing?

I would rather make the change in the TODO separately. I want to be sure that enabling this for both the Clang and GCC implementations of atomic will not cause ODR or ABI problems. I think these concerns should be addressed in a different patch.

mclow.lists accepted this revision.Aug 19 2015, 9:19 AM
mclow.lists edited edge metadata.

I think this is ready to land now. Thanks, Eric.

This revision is now accepted and ready to land.Aug 19 2015, 9:19 AM
EricWF closed this revision.Aug 19 2015, 10:22 AM