Author: vsapsai Date: Wed May 2 10:56:45 2018 New Revision: 331379 URL: http://llvm.org/viewvc/llvm-project?rev=331379&view=rev Log: Emit an error when mixing <stdatomic.h> and <atomic>
Atomics in C and C++ are incompatible at the moment and mixing the headers can result in confusing error messages. Emit an error explicitly telling about the incompatibility. Introduce the macro `__ALLOW_STDC_ATOMICS_IN_CXX__` that allows to choose in C++ between C atomics and C++ atomics. rdar://problem/27435938 Reviewers: rsmith, EricWF, mclow.lists Reviewed By: mclow.lists Subscribers: jkorous-apple, christof, bumblebritches57, JonChesterfield, smeenai, cfe-commits Differential Revision: https://reviews.llvm.org/D45470 Added: libcxx/trunk/test/libcxx/atomics/c_compatibility.fail.cpp Modified: libcxx/trunk/include/atomic Modified: libcxx/trunk/include/atomic URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/atomic?rev=331379&r1=331378&r2=331379&view=diff ============================================================================== --- libcxx/trunk/include/atomic (original) +++ libcxx/trunk/include/atomic Wed May 2 10:56:45 2018 @@ -555,6 +555,9 @@ void atomic_signal_fence(memory_order m) #if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) #error <atomic> is not implemented #endif +#ifdef __ALLOW_STDC_ATOMICS_IN_CXX__ +#error <stdatomic.h> is incompatible with the C++ standard library +#endif #if _LIBCPP_STD_VER > 14 # define __cpp_lib_atomic_is_always_lock_free 201603L Added: libcxx/trunk/test/libcxx/atomics/c_compatibility.fail.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/atomics/c_compatibility.fail.cpp?rev=331379&view=auto ============================================================================== --- libcxx/trunk/test/libcxx/atomics/c_compatibility.fail.cpp (added) +++ libcxx/trunk/test/libcxx/atomics/c_compatibility.fail.cpp Wed May 2 10:56:45 2018 @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// +// <atomic> + +// Test that including <atomic> fails to compile when we want to use C atomics +// in C++ and have corresponding macro defined. + +// MODULES_DEFINES: __ALLOW_STDC_ATOMICS_IN_CXX__ +#ifndef __ALLOW_STDC_ATOMICS_IN_CXX__ +#define __ALLOW_STDC_ATOMICS_IN_CXX__ +#endif + +#include <atomic> +// expected-error@atomic:* {{<stdatomic.h> is incompatible with the C++ standard library}} + +int main() +{ +} + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits