diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -583,7 +583,7 @@ endif() target_add_compile_flags_if_supported(${target} PRIVATE -Wextra -W -Wwrite-strings -Wno-unused-parameter -Wno-long-long - -Werror=return-type -Wextra-semi) + -Werror=return-type -Wextra-semi -Wundef) if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") target_add_compile_flags_if_supported(${target} PRIVATE -Wno-user-defined-literals diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -183,11 +183,12 @@ #define __has_include(...) 0 #endif -#if defined(__clang__) -# define _LIBCPP_COMPILER_CLANG -# ifndef __apple_build_version__ -# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__) -# endif +#if defined(__apple_build_version__) +# define _LIBCPP_COMPILER_CLANG_BASED +# define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000) +#elif defined(__clang__) +# define _LIBCPP_COMPILER_CLANG_BASED +# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__) #elif defined(__GNUC__) # define _LIBCPP_COMPILER_GCC #elif defined(_MSC_VER) @@ -350,7 +351,7 @@ # define _LIBCPP_NO_CFI #endif -#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L +#if (defined(__ISO_C_VISIBLE) && (__ISO_C_VISIBLE >= 2011)) || __cplusplus >= 201103L # if defined(__FreeBSD__) # define _LIBCPP_HAS_ALIGNED_ALLOC # define _LIBCPP_HAS_QUICK_EXIT @@ -404,7 +405,7 @@ #ifndef _LIBCPP_CXX03_LANG # define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) -#elif defined(_LIBCPP_COMPILER_CLANG) +#elif defined(_LIBCPP_COMPILER_CLANG_BASED) # define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) #else # error "We don't know a correct way to implement alignof(T) in C++03 outside of Clang" @@ -412,7 +413,7 @@ #define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) -#if defined(_LIBCPP_COMPILER_CLANG) +#if defined(_LIBCPP_COMPILER_CLANG_BASED) #if defined(_LIBCPP_ALTERNATE_STRING_LAYOUT) # error _LIBCPP_ALTERNATE_STRING_LAYOUT is deprecated, please use _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT instead @@ -510,8 +511,8 @@ #define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__)) // Literal operators ""d and ""y are supported starting with LLVM Clang 8 and AppleClang 10.0.1 -#if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 800) || \ - (defined(__apple_build_version__) && __apple_build_version__ < 10010000) +#if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 800) || \ + (defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1001) #define _LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS #endif @@ -1028,8 +1029,8 @@ #endif // Macros to enter and leave a state where deprecation warnings are suppressed. -#if !defined(_LIBCPP_SUPPRESS_DEPRECATED_PUSH) && \ - (defined(_LIBCPP_COMPILER_CLANG) || defined(_LIBCPP_COMPILER_GCC)) +#if !defined(_LIBCPP_SUPPRESS_DEPRECATED_PUSH) && \ + (defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)) # define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") @@ -1069,7 +1070,7 @@ // NODISCARD macros to the correct attribute. #if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC) # define _LIBCPP_NODISCARD_ATTRIBUTE [[nodiscard]] -#elif defined(_LIBCPP_COMPILER_CLANG) && !defined(_LIBCPP_CXX03_LANG) +#elif defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(_LIBCPP_CXX03_LANG) # define _LIBCPP_NODISCARD_ATTRIBUTE [[clang::warn_unused_result]] #else // We can't use GCC's [[gnu::warn_unused_result]] and @@ -1119,7 +1120,7 @@ #endif // Try to find out if RTTI is disabled. -#if defined(_LIBCPP_COMPILER_CLANG) && !__has_feature(cxx_rtti) +#if defined(_LIBCPP_COMPILER_CLANG_BASED) && !__has_feature(cxx_rtti) # define _LIBCPP_NO_RTTI #elif defined(__GNUC__) && !defined(__GXX_RTTI) # define _LIBCPP_NO_RTTI diff --git a/libcxx/include/experimental/simd b/libcxx/include/experimental/simd --- a/libcxx/include/experimental/simd +++ b/libcxx/include/experimental/simd @@ -725,12 +725,12 @@ template struct __vec_ext_traits { -#if !defined(_LIBCPP_COMPILER_CLANG) +#if !defined(_LIBCPP_COMPILER_CLANG_BASED) typedef _Tp type __attribute__((vector_size(__ceil_pow_of_2(__bytes)))); #endif }; -#if defined(_LIBCPP_COMPILER_CLANG) +#if defined(_LIBCPP_COMPILER_CLANG_BASED) #define _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, _NUM_ELEMENT) \ template <> \ struct __vec_ext_traits<_TYPE, sizeof(_TYPE) * _NUM_ELEMENT> { \ diff --git a/libcxx/include/ext/hash_map b/libcxx/include/ext/hash_map --- a/libcxx/include/ext/hash_map +++ b/libcxx/include/ext/hash_map @@ -208,7 +208,7 @@ #include #include -#if __DEPRECATED +#if defined(__DEPRECATED) && __DEPRECATED #if defined(_LIBCPP_WARNING) _LIBCPP_WARNING("Use of the header is deprecated. Migrate to ") #else diff --git a/libcxx/include/ext/hash_set b/libcxx/include/ext/hash_set --- a/libcxx/include/ext/hash_set +++ b/libcxx/include/ext/hash_set @@ -197,7 +197,7 @@ #include #include -#if __DEPRECATED +#if defined(__DEPRECATED) && __DEPRECATED #if defined(_LIBCPP_WARNING) _LIBCPP_WARNING("Use of the header is deprecated. Migrate to ") #else diff --git a/libcxx/include/future b/libcxx/include/future --- a/libcxx/include/future +++ b/libcxx/include/future @@ -501,9 +501,7 @@ error_code __ec_; public: future_error(error_code __ec); -#if _LIBCPP_STD_VERS > 14 - explicit future_error(future_errc _Ev) : logic_error(), __ec_(make_error_code(_Ev)) {} -#endif + _LIBCPP_INLINE_VISIBILITY const error_code& code() const _NOEXCEPT {return __ec_;} diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits --- a/libcxx/include/type_traits +++ b/libcxx/include/type_traits @@ -834,8 +834,10 @@ // is_pointer -// Before Clang 11, __is_pointer didn't work for Objective-C types. -#if __has_keyword(__is_pointer) && !(defined(_LIBCPP_COMPILER_CLANG) && _LIBCPP_CLANG_VER < 1100) +// Before Clang 11 / AppleClang 12.0.5, __is_pointer didn't work for Objective-C types. +#if __has_keyword(__is_pointer) && \ + !(defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1100) && \ + !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1205) template struct _LIBCPP_TEMPLATE_VIS is_pointer : _BoolConstant<__is_pointer(_Tp)> { }; @@ -1131,7 +1133,9 @@ // Before Clang 10, __is_fundamental didn't work for nullptr_t. // In C++03 nullptr_t is library-provided but must still count as "fundamental." -#if __has_keyword(__is_fundamental) && !(defined(_LIBCPP_COMPILER_CLANG) && _LIBCPP_CLANG_VER < 1000) && !defined(_LIBCPP_CXX03_LANG) +#if __has_keyword(__is_fundamental) && \ + !(defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1000) && \ + !defined(_LIBCPP_CXX03_LANG) template struct _LIBCPP_TEMPLATE_VIS is_fundamental : _BoolConstant<__is_fundamental(_Tp)> { }; @@ -1416,7 +1420,8 @@ // is_signed // Before Clang 10, __is_signed didn't work for floating-point types or enums. -#if __has_keyword(__is_signed) && !(defined(_LIBCPP_COMPILER_CLANG) && _LIBCPP_CLANG_VER < 1000) +#if __has_keyword(__is_signed) && \ + !(defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1000) template struct _LIBCPP_TEMPLATE_VIS is_signed : _BoolConstant<__is_signed(_Tp)> { }; @@ -1452,7 +1457,10 @@ // is_unsigned // Before Clang 13, __is_unsigned returned true for enums with signed underlying type. -#if __has_keyword(__is_unsigned) && !(defined(_LIBCPP_COMPILER_CLANG) && _LIBCPP_CLANG_VER < 1300) +// No currently-released version of AppleClang contains the fixed intrinsic. +#if __has_keyword(__is_unsigned) && \ + !(defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1300) && \ + !defined(_LIBCPP_APPLE_CLANG_VER) template struct _LIBCPP_TEMPLATE_VIS is_unsigned : _BoolConstant<__is_unsigned(_Tp)> { }; diff --git a/libcxx/test/std/atomics/types.pass.cpp b/libcxx/test/std/atomics/types.pass.cpp --- a/libcxx/test/std/atomics/types.pass.cpp +++ b/libcxx/test/std/atomics/types.pass.cpp @@ -24,12 +24,13 @@ #include #include + +#include "test_macros.h" + #if TEST_STD_VER >= 20 # include #endif -#include "test_macros.h" - template struct test_atomic { diff --git a/libcxx/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq_all_zero.pass.cpp b/libcxx/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq_all_zero.pass.cpp --- a/libcxx/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq_all_zero.pass.cpp +++ b/libcxx/test/std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq_all_zero.pass.cpp @@ -25,11 +25,8 @@ #include #include #include -#if TEST_STD_VER >= 11 -#include #include "test_macros.h" -#endif struct all_zero_seed_seq { typedef unsigned int result_type; diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp @@ -19,11 +19,11 @@ #include #include +#include "test_macros.h" + #if TEST_STD_VER >= 11 #include "poisoned_hash_helper.h" -#include "test_macros.h" - struct A {}; #endif diff --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h --- a/libcxx/test/support/test_macros.h +++ b/libcxx/test/support/test_macros.h @@ -165,7 +165,8 @@ // Sniff out to see if the underlying C library has C11 features // This is cribbed from __config; but lives here as well because we can't assume libc++ -#if __ISO_C_VISIBLE >= 2011 || TEST_STD_VER >= 11 +#if (defined(__ISO_C_VISIBLE) && (__ISO_C_VISIBLE >= 2011)) || \ + TEST_STD_VER >= 11 # if defined(__FreeBSD__) # if __FreeBSD_version >= 1300064 || \ (__FreeBSD_version >= 1201504 && __FreeBSD_version < 1300000) diff --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py --- a/libcxx/utils/libcxx/test/params.py +++ b/libcxx/utils/libcxx/test/params.py @@ -14,6 +14,7 @@ '-Wall', '-Wextra', '-Wshadow', + '-Wundef', '-Wno-unused-command-line-argument', '-Wno-attributes', '-Wno-pessimizing-move',