Skip to content

Commit

Permalink
Emit an error when mixing <stdatomic.h> and <atomic>
Browse files Browse the repository at this point in the history
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

llvm-svn: 331378
  • Loading branch information
vsapsai committed May 2, 2018
1 parent dcc815d commit c0a278a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clang/lib/Headers/stdatomic.h
Expand Up @@ -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>

Expand Down
10 changes: 10 additions & 0 deletions clang/test/Headers/stdatomic.cpp
@@ -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@stdatomic.h:* {{<stdatomic.h> is incompatible with the C++ standard library}}
#else
// expected-no-diagnostics
#endif

0 comments on commit c0a278a

Please sign in to comment.