r331378 - Emit an error when mixing <stdatomic.h> and <atomic>

Volodymyr Sapsai via cfe-commits cfe-commits at lists.llvm.org
Wed May 2 10:50:43 PDT 2018


Author: vsapsai
Date: Wed May  2 10:50:43 2018
New Revision: 331378

URL: http://llvm.org/viewvc/llvm-project?rev=331378&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:
    cfe/trunk/test/Headers/stdatomic.cpp
Modified:
    cfe/trunk/lib/Headers/stdatomic.h

Modified: cfe/trunk/lib/Headers/stdatomic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/stdatomic.h?rev=331378&r1=331377&r2=331378&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/stdatomic.h (original)
+++ cfe/trunk/lib/Headers/stdatomic.h Wed May  2 10:50:43 2018
@@ -31,6 +31,10 @@
 # include_next <stdatomic.h>
 #else
 
+#if !defined(__ALLOW_STDC_ATOMICS_IN_CXX__) && defined(__cplusplus)
+#error "<stdatomic.h> is incompatible with the C++ standard library; define __ALLOW_STDC_ATOMICS_IN_CXX__ to proceed."
+#endif
+
 #include <stddef.h>
 #include <stdint.h>
 

Added: cfe/trunk/test/Headers/stdatomic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/stdatomic.cpp?rev=331378&view=auto
==============================================================================
--- cfe/trunk/test/Headers/stdatomic.cpp (added)
+++ cfe/trunk/test/Headers/stdatomic.cpp Wed May  2 10:50:43 2018
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -verify
+// RUN: %clang_cc1 -D__ALLOW_STDC_ATOMICS_IN_CXX__ %s -verify
+
+#include <stdatomic.h>
+
+#ifndef __ALLOW_STDC_ATOMICS_IN_CXX__
+// expected-error at stdatomic.h:* {{<stdatomic.h> is incompatible with the C++ standard library}}
+#else
+// expected-no-diagnostics
+#endif




More information about the cfe-commits mailing list