[libc++] Build and test with -Wundef warning. NFC.

This will avoid typos like `_LIBCPP_STD_VERS` (<future>) or using `#if TEST_STD_VER > 17` without including "test_macros.h".

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D99515
This commit is contained in:
Marek Kurdej 2021-04-01 08:29:55 +02:00
parent a1d83776bf
commit 5c703f0fd8
12 changed files with 42 additions and 35 deletions

View File

@ -583,7 +583,7 @@ function(cxx_add_warning_flags target)
endif() endif()
target_add_compile_flags_if_supported(${target} PRIVATE -Wextra -W -Wwrite-strings target_add_compile_flags_if_supported(${target} PRIVATE -Wextra -W -Wwrite-strings
-Wno-unused-parameter -Wno-long-long -Wno-unused-parameter -Wno-long-long
-Werror=return-type -Wextra-semi) -Werror=return-type -Wextra-semi -Wundef)
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
target_add_compile_flags_if_supported(${target} PRIVATE target_add_compile_flags_if_supported(${target} PRIVATE
-Wno-user-defined-literals -Wno-user-defined-literals

View File

@ -183,11 +183,12 @@
#define __has_include(...) 0 #define __has_include(...) 0
#endif #endif
#if defined(__clang__) #if defined(__apple_build_version__)
# define _LIBCPP_COMPILER_CLANG # define _LIBCPP_COMPILER_CLANG_BASED
# ifndef __apple_build_version__ # define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000)
# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__) #elif defined(__clang__)
# endif # define _LIBCPP_COMPILER_CLANG_BASED
# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
#elif defined(__GNUC__) #elif defined(__GNUC__)
# define _LIBCPP_COMPILER_GCC # define _LIBCPP_COMPILER_GCC
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
@ -350,7 +351,7 @@
# define _LIBCPP_NO_CFI # define _LIBCPP_NO_CFI
#endif #endif
#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L #if (defined(__ISO_C_VISIBLE) && (__ISO_C_VISIBLE >= 2011)) || __cplusplus >= 201103L
# if defined(__FreeBSD__) # if defined(__FreeBSD__)
# define _LIBCPP_HAS_ALIGNED_ALLOC # define _LIBCPP_HAS_ALIGNED_ALLOC
# define _LIBCPP_HAS_QUICK_EXIT # define _LIBCPP_HAS_QUICK_EXIT
@ -404,7 +405,7 @@
#ifndef _LIBCPP_CXX03_LANG #ifndef _LIBCPP_CXX03_LANG
# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) # define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
#elif defined(_LIBCPP_COMPILER_CLANG) #elif defined(_LIBCPP_COMPILER_CLANG_BASED)
# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) # define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
#else #else
# error "We don't know a correct way to implement alignof(T) in C++03 outside of Clang" # 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) #define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
#if defined(_LIBCPP_COMPILER_CLANG) #if defined(_LIBCPP_COMPILER_CLANG_BASED)
#if defined(_LIBCPP_ALTERNATE_STRING_LAYOUT) #if defined(_LIBCPP_ALTERNATE_STRING_LAYOUT)
# error _LIBCPP_ALTERNATE_STRING_LAYOUT is deprecated, please use _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT instead # error _LIBCPP_ALTERNATE_STRING_LAYOUT is deprecated, please use _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT instead
@ -510,8 +511,8 @@ typedef __char32_t char32_t;
#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__)) #define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
// Literal operators ""d and ""y are supported starting with LLVM Clang 8 and AppleClang 10.0.1 // 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) || \ #if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 800) || \
(defined(__apple_build_version__) && __apple_build_version__ < 10010000) (defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1001)
#define _LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS #define _LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS
#endif #endif
@ -1028,8 +1029,8 @@ typedef unsigned int char32_t;
#endif #endif
// Macros to enter and leave a state where deprecation warnings are suppressed. // Macros to enter and leave a state where deprecation warnings are suppressed.
#if !defined(_LIBCPP_SUPPRESS_DEPRECATED_PUSH) && \ #if !defined(_LIBCPP_SUPPRESS_DEPRECATED_PUSH) && \
(defined(_LIBCPP_COMPILER_CLANG) || defined(_LIBCPP_COMPILER_GCC)) (defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC))
# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ # define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
_Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wdeprecated\"") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")
@ -1069,7 +1070,7 @@ typedef unsigned int char32_t;
// NODISCARD macros to the correct attribute. // NODISCARD macros to the correct attribute.
#if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC) #if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC)
# define _LIBCPP_NODISCARD_ATTRIBUTE [[nodiscard]] # 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]] # define _LIBCPP_NODISCARD_ATTRIBUTE [[clang::warn_unused_result]]
#else #else
// We can't use GCC's [[gnu::warn_unused_result]] and // We can't use GCC's [[gnu::warn_unused_result]] and
@ -1119,7 +1120,7 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
#endif #endif
// Try to find out if RTTI is disabled. // 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 # define _LIBCPP_NO_RTTI
#elif defined(__GNUC__) && !defined(__GXX_RTTI) #elif defined(__GNUC__) && !defined(__GXX_RTTI)
# define _LIBCPP_NO_RTTI # define _LIBCPP_NO_RTTI

View File

@ -725,12 +725,12 @@ constexpr size_t __ceil_pow_of_2(size_t __val) {
template <class _Tp, size_t __bytes> template <class _Tp, size_t __bytes>
struct __vec_ext_traits { 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)))); typedef _Tp type __attribute__((vector_size(__ceil_pow_of_2(__bytes))));
#endif #endif
}; };
#if defined(_LIBCPP_COMPILER_CLANG) #if defined(_LIBCPP_COMPILER_CLANG_BASED)
#define _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, _NUM_ELEMENT) \ #define _LIBCPP_SPECIALIZE_VEC_EXT(_TYPE, _NUM_ELEMENT) \
template <> \ template <> \
struct __vec_ext_traits<_TYPE, sizeof(_TYPE) * _NUM_ELEMENT> { \ struct __vec_ext_traits<_TYPE, sizeof(_TYPE) * _NUM_ELEMENT> { \

View File

@ -208,7 +208,7 @@ template <class Key, class T, class Hash, class Pred, class Alloc>
#include <type_traits> #include <type_traits>
#include <ext/__hash> #include <ext/__hash>
#if __DEPRECATED #if defined(__DEPRECATED) && __DEPRECATED
#if defined(_LIBCPP_WARNING) #if defined(_LIBCPP_WARNING)
_LIBCPP_WARNING("Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>") _LIBCPP_WARNING("Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>")
#else #else

View File

@ -197,7 +197,7 @@ template <class Value, class Hash, class Pred, class Alloc>
#include <functional> #include <functional>
#include <ext/__hash> #include <ext/__hash>
#if __DEPRECATED #if defined(__DEPRECATED) && __DEPRECATED
#if defined(_LIBCPP_WARNING) #if defined(_LIBCPP_WARNING)
_LIBCPP_WARNING("Use of the header <ext/hash_set> is deprecated. Migrate to <unordered_set>") _LIBCPP_WARNING("Use of the header <ext/hash_set> is deprecated. Migrate to <unordered_set>")
#else #else

View File

@ -501,9 +501,7 @@ class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_FUTURE_ERROR future_error
error_code __ec_; error_code __ec_;
public: public:
future_error(error_code __ec); 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 _LIBCPP_INLINE_VISIBILITY
const error_code& code() const _NOEXCEPT {return __ec_;} const error_code& code() const _NOEXCEPT {return __ec_;}

View File

@ -834,8 +834,10 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_array_v
// is_pointer // is_pointer
// Before Clang 11, __is_pointer didn't work for Objective-C types. // Before Clang 11 / AppleClang 12.0.5, __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_CLANG_VER) && _LIBCPP_CLANG_VER < 1100) && \
!(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1205)
template<class _Tp> template<class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_pointer : _BoolConstant<__is_pointer(_Tp)> { }; struct _LIBCPP_TEMPLATE_VIS is_pointer : _BoolConstant<__is_pointer(_Tp)> { };
@ -1131,7 +1133,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_arithmetic_v
// Before Clang 10, __is_fundamental didn't work for nullptr_t. // 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." // 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<class _Tp> template<class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_fundamental : _BoolConstant<__is_fundamental(_Tp)> { }; struct _LIBCPP_TEMPLATE_VIS is_fundamental : _BoolConstant<__is_fundamental(_Tp)> { };
@ -1416,7 +1420,8 @@ template<class _Tp> using type_identity_t = typename type_identity<_Tp>::type;
// is_signed // is_signed
// Before Clang 10, __is_signed didn't work for floating-point types or enums. // 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<class _Tp> template<class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_signed : _BoolConstant<__is_signed(_Tp)> { }; struct _LIBCPP_TEMPLATE_VIS is_signed : _BoolConstant<__is_signed(_Tp)> { };
@ -1452,7 +1457,10 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_signed_v
// is_unsigned // is_unsigned
// Before Clang 13, __is_unsigned returned true for enums with signed underlying type. // 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<class _Tp> template<class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_unsigned : _BoolConstant<__is_unsigned(_Tp)> { }; struct _LIBCPP_TEMPLATE_VIS is_unsigned : _BoolConstant<__is_unsigned(_Tp)> { };

View File

@ -24,12 +24,13 @@
#include <thread> #include <thread>
#include <chrono> #include <chrono>
#include "test_macros.h"
#if TEST_STD_VER >= 20 #if TEST_STD_VER >= 20
# include <memory> # include <memory>
#endif #endif
#include "test_macros.h"
template <class A, bool Integral> template <class A, bool Integral>
struct test_atomic struct test_atomic
{ {

View File

@ -25,11 +25,8 @@
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <cstddef> #include <cstddef>
#if TEST_STD_VER >= 11
#include <initializer_list>
#include "test_macros.h" #include "test_macros.h"
#endif
struct all_zero_seed_seq { struct all_zero_seed_seq {
typedef unsigned int result_type; typedef unsigned int result_type;

View File

@ -19,11 +19,11 @@
#include <memory> #include <memory>
#include <cassert> #include <cassert>
#include "test_macros.h"
#if TEST_STD_VER >= 11 #if TEST_STD_VER >= 11
#include "poisoned_hash_helper.h" #include "poisoned_hash_helper.h"
#include "test_macros.h"
struct A {}; struct A {};
#endif #endif

View File

@ -165,7 +165,8 @@
// Sniff out to see if the underlying C library has C11 features // 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++ // 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 defined(__FreeBSD__)
# if __FreeBSD_version >= 1300064 || \ # if __FreeBSD_version >= 1300064 || \
(__FreeBSD_version >= 1201504 && __FreeBSD_version < 1300000) (__FreeBSD_version >= 1201504 && __FreeBSD_version < 1300000)

View File

@ -14,6 +14,7 @@ _warningFlags = [
'-Wall', '-Wall',
'-Wextra', '-Wextra',
'-Wshadow', '-Wshadow',
'-Wundef',
'-Wno-unused-command-line-argument', '-Wno-unused-command-line-argument',
'-Wno-attributes', '-Wno-attributes',
'-Wno-pessimizing-move', '-Wno-pessimizing-move',