diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -581,7 +581,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 @@ -348,7 +348,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 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 @@ -835,7 +835,9 @@ // 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) +#if __has_keyword(__is_pointer) && \ + !(defined(_LIBCPP_COMPILER_CLANG) && defined(_LIBCPP_CLANG_VER) && \ + _LIBCPP_CLANG_VER < 1100) template struct _LIBCPP_TEMPLATE_VIS is_pointer : _BoolConstant<__is_pointer(_Tp)> { }; @@ -1131,7 +1133,10 @@ // 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_COMPILER_CLANG) && 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 +1421,9 @@ // 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_COMPILER_CLANG) && defined(_LIBCPP_CLANG_VER) && \ + _LIBCPP_CLANG_VER < 1000) template struct _LIBCPP_TEMPLATE_VIS is_signed : _BoolConstant<__is_signed(_Tp)> { }; @@ -1452,7 +1459,9 @@ // 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) +#if __has_keyword(__is_unsigned) && \ + !(defined(_LIBCPP_COMPILER_CLANG) && defined(_LIBCPP_CLANG_VER) && \ + _LIBCPP_CLANG_VER < 1300) 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',