Skip to content

Commit 1bef51a

Browse files
committed
Introduce a new test macro TEST_HAS_C11_FEATURES which is set when the underlying C library has C11 features. In C++17, we use those features. <__config> defines a similar macro, _LIBCPP_HAS_C11_FEATURES, but we don't want to use that in the library-independent parts of the tests, so define the new one. Also add a libc++-specific test to make sure the two stay in sync.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@338411 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent decf28e commit 1bef51a

File tree

2 files changed

+66
-10
lines changed

2 files changed

+66
-10
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is dual licensed under the MIT and the University of Illinois Open
6+
// Source Licenses. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
// UNSUPPORTED: c++98, c++03, c++11, c++14
10+
11+
// We have two macros for checking whether or not the underlying C library
12+
// has C11 features:
13+
// TEST_HAS_C11_FEATURES - which is defined in "test_macros.h"
14+
// _LIBCPP_HAS_C11_FEATURES - which is defined in <__config>
15+
// They should always be the same
16+
17+
#ifdef TEST_HAS_C11_FEATURES
18+
# ifndef _LIBCPP_HAS_C11_FEATURES
19+
# error "TEST_HAS_C11_FEATURES is defined, but _LIBCPP_HAS_C11_FEATURES is not"
20+
# endif
21+
#endif
22+
23+
#ifdef _LIBCPP_HAS_C11_FEATURES
24+
# ifndef TEST_HAS_C11_FEATURES
25+
# error "_LIBCPP_HAS_C11_FEATURES is defined, but TEST_HAS_C11_FEATURES is not"
26+
# endif
27+
#endif
28+
29+
int main() {}

test/support/test_macros.h

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,6 @@
9494
#define TEST_GLIBC_PREREQ(major, minor) __GLIBC_PREREQ(major, minor)
9595
#endif
9696

97-
/* Features that were introduced in C++14 */
98-
#if TEST_STD_VER >= 14
99-
#define TEST_HAS_EXTENDED_CONSTEXPR
100-
#define TEST_HAS_VARIABLE_TEMPLATES
101-
#endif
102-
103-
/* Features that were introduced after C++14 */
104-
#if TEST_STD_VER > 14
105-
#endif
106-
10797
#if TEST_STD_VER >= 11
10898
#define TEST_ALIGNOF(...) alignof(__VA_ARGS__)
10999
#define TEST_ALIGNAS(...) alignas(__VA_ARGS__)
@@ -132,6 +122,43 @@
132122
#define TEST_THROW_SPEC(...) throw(__VA_ARGS__)
133123
#endif
134124

125+
// Sniff out to see if the underling C library has C11 features
126+
// Note that at this time (July 2018), MacOS X and iOS do NOT.
127+
#if __ISO_C_VISIBLE >= 2011
128+
# if defined(__FreeBSD__)
129+
# define TEST_HAS_C11_FEATURES
130+
# elif defined(__Fuchsia__)
131+
# define TEST_HAS_C11_FEATURES
132+
# elif defined(__linux__)
133+
# if !defined(_LIBCPP_HAS_MUSL_LIBC)
134+
# if _LIBCPP_GLIBC_PREREQ(2, 17)
135+
# define TEST_HAS_C11_FEATURES
136+
# endif
137+
# else // defined(_LIBCPP_HAS_MUSL_LIBC)
138+
# define TEST_HAS_C11_FEATURES
139+
# endif
140+
# elif defined(_WIN32)
141+
# if defined(_MSC_VER) && !defined(__MINGW32__)
142+
# define TEST_HAS_C11_FEATURES // Using Microsoft's C Runtime library
143+
# endif
144+
# endif
145+
#endif
146+
147+
/* Features that were introduced in C++14 */
148+
#if TEST_STD_VER >= 14
149+
#define TEST_HAS_EXTENDED_CONSTEXPR
150+
#define TEST_HAS_VARIABLE_TEMPLATES
151+
#endif
152+
153+
/* Features that were introduced in C++17 */
154+
#if TEST_STD_VER >= 17
155+
#endif
156+
157+
/* Features that were introduced after C++17 */
158+
#if TEST_STD_VER > 17
159+
#endif
160+
161+
135162
#define TEST_ALIGNAS_TYPE(...) TEST_ALIGNAS(TEST_ALIGNOF(__VA_ARGS__))
136163

137164
#if !TEST_HAS_FEATURE(cxx_rtti) && !defined(__cpp_rtti) \

0 commit comments

Comments
 (0)