Skip to content

Commit 292a28d

Browse files
authored
[libc++] Enable availability based on the compiler instead of __has_extension (#84065)
__has_extension(...) doesn't work as intended when -pedantic-errors is used with Clang. With that flag, __has_extension(...) is equivalent to __has_feature(...), which means that checks like __has_extension(pragma_clang_attribute_external_declaration) will return 0. In turn, this has the effect of disabling availability markup in libc++, which is undesirable. rdar://124078119
1 parent a10fd16 commit 292a28d

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

libcxx/include/__availability

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,10 @@
7272
# endif
7373
#endif
7474

75-
// Availability markup is disabled when building the library, or when the compiler
75+
// Availability markup is disabled when building the library, or when a non-Clang
76+
// compiler is used because only Clang supports the necessary attributes.
7677
// doesn't support the proper attributes.
77-
#if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCXXABI_BUILDING_LIBRARY) || \
78-
!__has_feature(attribute_availability_with_strict) || !__has_feature(attribute_availability_in_templates) || \
79-
!__has_extension(pragma_clang_attribute_external_declaration)
78+
#if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCXXABI_BUILDING_LIBRARY) || !defined(_LIBCPP_COMPILER_CLANG_BASED)
8079
# if !defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
8180
# define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS
8281
# endif
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: stdlib=apple-libc++
10+
11+
// Test that using -pedantic-errors doesn't turn off availability annotations.
12+
// This used to be the case because we used __has_extension(...) to enable the
13+
// availability annotations, and -pedantic-errors changes the behavior of
14+
// __has_extension(...) in an incompatible way.
15+
16+
// ADDITIONAL_COMPILE_FLAGS: -pedantic-errors
17+
18+
#include <__availability>
19+
20+
#if defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS)
21+
# error Availability annotations should be enabled on Apple platforms in the system configuration!
22+
#endif

0 commit comments

Comments
 (0)