EricWF created this revision.
Herald added a subscriber: krytarowski.
This patch improves how libc++ handles min/max macros within the headers.
Previously libc++ would undef them and emit a warning.
This patch changes libc++ to use `#pragma push_macro` to save the macro before
undefining it, and `#pragma pop_macro` to restore the macros and the end of the
header.
https://reviews.llvm.org/D33080
Files:
include/__bit_reference
include/__config
include/__hash_table
include/__mutex_base
include/__split_buffer
include/__std_stream
include/__string
include/__threading_support
include/__tree
include/__undef_macros
include/__undef_min_max
include/algorithm
include/array
include/bitset
include/chrono
include/deque
include/experimental/algorithm
include/experimental/functional
include/experimental/optional
include/forward_list
include/fstream
include/istream
include/limits
include/list
include/locale
include/memory
include/module.modulemap
include/mutex
include/optional
include/random
include/ratio
include/regex
include/shared_mutex
include/sstream
include/string
include/string_view
include/valarray
include/vector
test/libcxx/min_max_macros.sh.cpp
Index: test/libcxx/min_max_macros.sh.cpp
===================================================================
--- /dev/null
+++ test/libcxx/min_max_macros.sh.cpp
@@ -0,0 +1,295 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Test that we are not affected by min/max macro definitions
+
+// RUN: %compile -fsyntax-only
+
+#define min true
+#define max true
+
+#define TEST_MIN_MAX() static_assert(min == true && max == true, "")
+
+
+// Top level headers
+#include <algorithm>
+TEST_MIN_MAX();
+#include <any>
+TEST_MIN_MAX();
+#include <array>
+TEST_MIN_MAX();
+#ifndef _LIBCPP_HAS_NO_THREADS
+#include <atomic>
+TEST_MIN_MAX();
+#endif
+#include <bitset>
+TEST_MIN_MAX();
+#include <cassert>
+TEST_MIN_MAX();
+#include <ccomplex>
+TEST_MIN_MAX();
+#include <cctype>
+TEST_MIN_MAX();
+#include <cerrno>
+TEST_MIN_MAX();
+#include <cfenv>
+TEST_MIN_MAX();
+#include <cfloat>
+TEST_MIN_MAX();
+#include <chrono>
+TEST_MIN_MAX();
+#include <cinttypes>
+TEST_MIN_MAX();
+#include <ciso646>
+TEST_MIN_MAX();
+#include <climits>
+TEST_MIN_MAX();
+#include <clocale>
+TEST_MIN_MAX();
+#include <cmath>
+TEST_MIN_MAX();
+#include <codecvt>
+TEST_MIN_MAX();
+#include <complex>
+TEST_MIN_MAX();
+#include <complex.h>
+TEST_MIN_MAX();
+#include <condition_variable>
+TEST_MIN_MAX();
+#include <csetjmp>
+TEST_MIN_MAX();
+#include <csignal>
+TEST_MIN_MAX();
+#include <cstdarg>
+TEST_MIN_MAX();
+#include <cstdbool>
+TEST_MIN_MAX();
+#include <cstddef>
+TEST_MIN_MAX();
+#include <cstdint>
+TEST_MIN_MAX();
+#include <cstdio>
+TEST_MIN_MAX();
+#include <cstdlib>
+TEST_MIN_MAX();
+#include <cstring>
+TEST_MIN_MAX();
+#include <ctgmath>
+TEST_MIN_MAX();
+#include <ctime>
+TEST_MIN_MAX();
+#include <ctype.h>
+TEST_MIN_MAX();
+#include <cwchar>
+TEST_MIN_MAX();
+#include <cwctype>
+TEST_MIN_MAX();
+#include <deque>
+TEST_MIN_MAX();
+#include <errno.h>
+TEST_MIN_MAX();
+#include <exception>
+TEST_MIN_MAX();
+#include <float.h>
+TEST_MIN_MAX();
+#include <forward_list>
+TEST_MIN_MAX();
+#include <fstream>
+TEST_MIN_MAX();
+#include <functional>
+TEST_MIN_MAX();
+#ifndef _LIBCPP_HAS_NO_THREADS
+#include <future>
+TEST_MIN_MAX();
+#endif
+#include <initializer_list>
+TEST_MIN_MAX();
+#include <inttypes.h>
+TEST_MIN_MAX();
+#include <iomanip>
+TEST_MIN_MAX();
+#include <ios>
+TEST_MIN_MAX();
+#include <iosfwd>
+TEST_MIN_MAX();
+#include <iostream>
+TEST_MIN_MAX();
+#include <istream>
+TEST_MIN_MAX();
+#include <iterator>
+TEST_MIN_MAX();
+#include <limits>
+TEST_MIN_MAX();
+#include <limits.h>
+TEST_MIN_MAX();
+#include <list>
+TEST_MIN_MAX();
+#include <locale>
+TEST_MIN_MAX();
+#include <locale.h>
+TEST_MIN_MAX();
+#include <map>
+TEST_MIN_MAX();
+#include <math.h>
+TEST_MIN_MAX();
+#include <memory>
+TEST_MIN_MAX();
+#ifndef _LIBCPP_HAS_NO_THREADS
+#include <mutex>
+TEST_MIN_MAX();
+#endif
+#include <new>
+TEST_MIN_MAX();
+#include <numeric>
+TEST_MIN_MAX();
+#include <optional>
+TEST_MIN_MAX();
+#include <ostream>
+TEST_MIN_MAX();
+#include <queue>
+TEST_MIN_MAX();
+#include <random>
+TEST_MIN_MAX();
+#include <ratio>
+TEST_MIN_MAX();
+#include <regex>
+TEST_MIN_MAX();
+#include <scoped_allocator>
+TEST_MIN_MAX();
+#include <set>
+TEST_MIN_MAX();
+#include <setjmp.h>
+TEST_MIN_MAX();
+#ifndef _LIBCPP_HAS_NO_THREADS
+#include <shared_mutex>
+TEST_MIN_MAX();
+#endif
+#include <sstream>
+TEST_MIN_MAX();
+#include <stack>
+TEST_MIN_MAX();
+#include <stdbool.h>
+TEST_MIN_MAX();
+#include <stddef.h>
+TEST_MIN_MAX();
+#include <stdexcept>
+TEST_MIN_MAX();
+#include <stdint.h>
+TEST_MIN_MAX();
+#include <stdio.h>
+TEST_MIN_MAX();
+#include <stdlib.h>
+TEST_MIN_MAX();
+#include <streambuf>
+TEST_MIN_MAX();
+#include <string>
+TEST_MIN_MAX();
+#include <string.h>
+TEST_MIN_MAX();
+#include <string_view>
+TEST_MIN_MAX();
+#include <strstream>
+TEST_MIN_MAX();
+#include <system_error>
+TEST_MIN_MAX();
+#include <tgmath.h>
+TEST_MIN_MAX();
+#ifndef _LIBCPP_HAS_NO_THREADS
+#include <thread>
+TEST_MIN_MAX();
+#endif
+#include <tuple>
+TEST_MIN_MAX();
+#include <typeindex>
+TEST_MIN_MAX();
+#include <typeinfo>
+TEST_MIN_MAX();
+#include <type_traits>
+TEST_MIN_MAX();
+#include <unordered_map>
+TEST_MIN_MAX();
+#include <unordered_set>
+TEST_MIN_MAX();
+#include <utility>
+TEST_MIN_MAX();
+#include <valarray>
+TEST_MIN_MAX();
+#include <variant>
+TEST_MIN_MAX();
+#include <vector>
+TEST_MIN_MAX();
+#include <wchar.h>
+TEST_MIN_MAX();
+#include <wctype.h>
+TEST_MIN_MAX();
+
+// experimental headers
+#if __cplusplus >= 201103L
+#include <experimental/algorithm>
+TEST_MIN_MAX();
+#include <experimental/any>
+TEST_MIN_MAX();
+#include <experimental/chrono>
+TEST_MIN_MAX();
+#include <experimental/deque>
+TEST_MIN_MAX();
+#include <experimental/dynarray>
+TEST_MIN_MAX();
+#include <experimental/filesystem>
+TEST_MIN_MAX();
+#include <experimental/forward_list>
+TEST_MIN_MAX();
+#include <experimental/functional>
+TEST_MIN_MAX();
+#include <experimental/iterator>
+TEST_MIN_MAX();
+#include <experimental/list>
+TEST_MIN_MAX();
+#include <experimental/map>
+TEST_MIN_MAX();
+#include <experimental/memory_resource>
+TEST_MIN_MAX();
+#include <experimental/numeric>
+TEST_MIN_MAX();
+#include <experimental/optional>
+TEST_MIN_MAX();
+#include <experimental/propagate_const>
+TEST_MIN_MAX();
+#include <experimental/ratio>
+TEST_MIN_MAX();
+#include <experimental/regex>
+TEST_MIN_MAX();
+#include <experimental/set>
+TEST_MIN_MAX();
+#include <experimental/string>
+TEST_MIN_MAX();
+#include <experimental/string_view>
+TEST_MIN_MAX();
+#include <experimental/system_error>
+TEST_MIN_MAX();
+#include <experimental/tuple>
+TEST_MIN_MAX();
+#include <experimental/type_traits>
+TEST_MIN_MAX();
+#include <experimental/unordered_map>
+TEST_MIN_MAX();
+#include <experimental/unordered_set>
+TEST_MIN_MAX();
+#include <experimental/utility>
+TEST_MIN_MAX();
+#include <experimental/vector>
+TEST_MIN_MAX();
+#endif // __cplusplus >= 201103L
+
+// extended headers
+#include <ext/hash_map>
+TEST_MIN_MAX();
+#include <ext/hash_set>
+TEST_MIN_MAX();
Index: include/vector
===================================================================
--- include/vector
+++ include/vector
@@ -275,14 +275,18 @@
#include <__split_buffer>
#include <__functional_base>
-#include <__undef_min_max>
-
#include <__debug>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <bool>
@@ -3357,4 +3361,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_VECTOR
Index: include/valarray
===================================================================
--- include/valarray
+++ include/valarray
@@ -347,12 +347,16 @@
#include <functional>
#include <new>
-#include <__undef_min_max>
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
template<class _Tp> class _LIBCPP_TEMPLATE_VIS valarray;
@@ -4865,4 +4869,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_VALARRAY
Index: include/string_view
===================================================================
--- include/string_view
+++ include/string_view
@@ -167,7 +167,6 @@
*/
#include <__config>
-
#include <__string>
#include <algorithm>
#include <iterator>
@@ -179,6 +178,12 @@
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
template<class _CharT, class _Traits = char_traits<_CharT> >
@@ -792,4 +797,6 @@
#endif
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_STRING_VIEW
Index: include/string
===================================================================
--- include/string
+++ include/string
@@ -484,14 +484,18 @@
#include <cstdint>
#endif
-#include <__undef_min_max>
-
#include <__debug>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
// fpos
@@ -4041,4 +4045,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_STRING
Index: include/sstream
===================================================================
--- include/sstream
+++ include/sstream
@@ -175,12 +175,16 @@
#include <istream>
#include <string>
-#include <__undef_min_max>
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
// basic_stringbuf
@@ -970,4 +974,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_SSTREAM
Index: include/shared_mutex
===================================================================
--- include/shared_mutex
+++ include/shared_mutex
@@ -125,12 +125,16 @@
#include <__config>
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
#if _LIBCPP_STD_VER > 11 || defined(_LIBCPP_BUILDING_SHARED_MUTEX)
#include <__mutex_base>
-#include <__undef_min_max>
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
@@ -500,4 +504,6 @@
#endif // _LIBCPP_STD_VER > 11
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_SHARED_MUTEX
Index: include/regex
===================================================================
--- include/regex
+++ include/regex
@@ -765,12 +765,16 @@
#include <vector>
#include <deque>
-#include <__undef_min_max>
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
namespace regex_constants
@@ -6562,4 +6566,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_REGEX
Index: include/ratio
===================================================================
--- include/ratio
+++ include/ratio
@@ -83,12 +83,16 @@
#include <climits>
#include <type_traits>
-#include <__undef_min_max>
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
// __static_gcd
@@ -520,4 +524,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_RATIO
Index: include/random
===================================================================
--- include/random
+++ include/random
@@ -1646,12 +1646,16 @@
#include <istream>
#include <ostream>
-#include <__undef_min_max>
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
// __is_seed_sequence
@@ -6736,4 +6740,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_RANDOM
Index: include/optional
===================================================================
--- include/optional
+++ include/optional
@@ -146,7 +146,6 @@
#include <__config>
#include <__debug>
#include <__functional_base>
-#include <__undef_min_max>
#include <functional>
#include <initializer_list>
#include <new>
@@ -158,6 +157,12 @@
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
namespace std // purposefully not using versioning namespace
{
@@ -1315,4 +1320,6 @@
#endif // _LIBCPP_STD_VER > 14
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_OPTIONAL
Index: include/mutex
===================================================================
--- include/mutex
+++ include/mutex
@@ -196,12 +196,16 @@
#endif
#include <__threading_support>
-#include <__undef_min_max>
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
#ifndef _LIBCPP_HAS_NO_THREADS
@@ -696,4 +700,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_MUTEX
Index: include/module.modulemap
===================================================================
--- include/module.modulemap
+++ include/module.modulemap
@@ -484,7 +484,6 @@
module __string { header "__string" export * }
module __tree { header "__tree" export * }
module __tuple { header "__tuple" export * }
- module __undef_min_max { header "__undef_min_max" export * }
module experimental {
requires cplusplus11
Index: include/memory
===================================================================
--- include/memory
+++ include/memory
@@ -658,12 +658,16 @@
# include <atomic>
#endif
-#include <__undef_min_max>
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _ValueType>
@@ -5545,4 +5549,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_MEMORY
Index: include/locale
===================================================================
--- include/locale
+++ include/locale
@@ -208,18 +208,22 @@
#include <Availability.h>
#endif
-#include <__undef_min_max>
+#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
+#include <__bsd_locale_defaults.h>
+#else
+#include <__bsd_locale_fallbacks.h>
+#endif
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
-#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
-#include <__bsd_locale_defaults.h>
-#else
-#include <__bsd_locale_fallbacks.h>
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
#endif
+
_LIBCPP_BEGIN_NAMESPACE_STD
#if defined(__APPLE__) || defined(__FreeBSD__)
@@ -4274,4 +4278,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_LOCALE
Index: include/list
===================================================================
--- include/list
+++ include/list
@@ -177,14 +177,18 @@
#include <algorithm>
#include <type_traits>
-#include <__undef_min_max>
-
#include <__debug>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _VoidPtr> struct __list_node;
@@ -2415,4 +2419,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_LIST
Index: include/limits
===================================================================
--- include/limits
+++ include/limits
@@ -102,23 +102,26 @@
*/
#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
#include <type_traits>
-#include <__undef_min_max>
-
#if defined(_LIBCPP_COMPILER_MSVC)
#include "support/win32/limits_msvc_win32.h"
#endif // _LIBCPP_MSVCRT
#if defined(__IBMCPP__)
#include "support/ibm/limits.h"
#endif // __IBMCPP__
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
enum float_round_style
@@ -811,4 +814,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_LIMITS
Index: include/istream
===================================================================
--- include/istream
+++ include/istream
@@ -162,12 +162,16 @@
#include <__config>
#include <ostream>
-#include <__undef_min_max>
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _CharT, class _Traits>
@@ -1683,4 +1687,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_ISTREAM
Index: include/fstream
===================================================================
--- include/fstream
+++ include/fstream
@@ -171,12 +171,16 @@
#include <__locale>
#include <cstdio>
-#include <__undef_min_max>
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _CharT, class _Traits>
@@ -1476,4 +1480,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_FSTREAM
Index: include/forward_list
===================================================================
--- include/forward_list
+++ include/forward_list
@@ -167,19 +167,22 @@
*/
#include <__config>
-
#include <initializer_list>
#include <memory>
#include <limits>
#include <iterator>
#include <algorithm>
-#include <__undef_min_max>
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _VoidPtr> struct __forward_list_node;
@@ -1719,4 +1722,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_FORWARD_LIST
Index: include/experimental/optional
===================================================================
--- include/experimental/optional
+++ include/experimental/optional
@@ -143,6 +143,23 @@
#include <experimental/__config>
#include <functional>
#include <stdexcept>
+#if _LIBCPP_STD_VER > 11
+#include <initializer_list>
+#include <type_traits>
+#include <new>
+#include <__functional_base>
+#include <__debug>
+#endif
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS bad_optional_access
@@ -160,17 +177,6 @@
#if _LIBCPP_STD_VER > 11
-#include <initializer_list>
-#include <type_traits>
-#include <new>
-#include <__functional_base>
-#include <__undef_min_max>
-#include <__debug>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
_LIBCPP_BEGIN_NAMESPACE_LFTS
struct in_place_t {};
@@ -913,4 +919,6 @@
#endif // _LIBCPP_STD_VER > 11
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_EXPERIMENTAL_OPTIONAL
Index: include/experimental/functional
===================================================================
--- include/experimental/functional
+++ include/experimental/functional
@@ -89,21 +89,24 @@
#include <experimental/__config>
#include <functional>
-
#include <algorithm>
#include <type_traits>
#include <vector>
#include <array>
#include <unordered_map>
-#include <__undef_min_max>
-
#include <__debug>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_LFTS
#if _LIBCPP_STD_VER > 11
@@ -456,4 +459,6 @@
_LIBCPP_END_NAMESPACE_LFTS
+_LIBCPP_POP_MACROS
+
#endif /* _LIBCPP_EXPERIMENTAL_FUNCTIONAL */
Index: include/experimental/algorithm
===================================================================
--- include/experimental/algorithm
+++ include/experimental/algorithm
@@ -39,17 +39,20 @@
#include <algorithm>
#include <type_traits>
-#include <__undef_min_max>
-
#include <__debug>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
-_LIBCPP_BEGIN_NAMESPACE_LFTS
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+_LIBCPP_BEGIN_NAMESPACE_LFTS
+
template <class _ForwardIterator, class _Searcher>
_LIBCPP_INLINE_VISIBILITY
_ForwardIterator search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher &__s)
@@ -67,4 +70,6 @@
_LIBCPP_END_NAMESPACE_LFTS
+_LIBCPP_POP_MACROS
+
#endif /* _LIBCPP_EXPERIMENTAL_ALGORITHM */
Index: include/deque
===================================================================
--- include/deque
+++ include/deque
@@ -150,19 +150,23 @@
*/
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
#include <__config>
#include <__split_buffer>
#include <type_traits>
#include <initializer_list>
#include <iterator>
#include <algorithm>
#include <stdexcept>
-#include <__undef_min_max>
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -2900,4 +2904,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_DEQUE
Index: include/chrono
===================================================================
--- include/chrono
+++ include/chrono
@@ -305,12 +305,16 @@
#include <ratio>
#include <limits>
-#include <__undef_min_max>
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
@@ -1160,4 +1164,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_CHRONO
Index: include/bitset
===================================================================
--- include/bitset
+++ include/bitset
@@ -113,10 +113,6 @@
*/
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
#include <__config>
#include <__bit_reference>
#include <cstddef>
@@ -126,7 +122,15 @@
#include <iosfwd>
#include <__functional_base>
-#include <__undef_min_max>
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -1090,4 +1094,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_BITSET
Index: include/array
===================================================================
--- include/array
+++ include/array
@@ -113,6 +113,8 @@
#pragma GCC system_header
#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, size_t _Size>
Index: include/algorithm
===================================================================
--- include/algorithm
+++ include/algorithm
@@ -648,14 +648,18 @@
#include <intrin.h>
#endif
-#include <__undef_min_max>
-
#include <__debug>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
// I'd like to replace these with _VSTD::equal_to<void>, but can't because:
@@ -5881,4 +5885,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_ALGORITHM
Index: include/__undef_min_max
===================================================================
--- include/__undef_min_max
+++ /dev/null
@@ -1,33 +0,0 @@
-// -*- C++ -*-
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifdef min
-#if !defined(_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS)
-#if defined(_LIBCPP_WARNING)
-_LIBCPP_WARNING("macro min is incompatible with C++. Try #define NOMINMAX "
- "before any Windows header. #undefing min")
-#else
-#warning: macro min is incompatible with C++. #undefing min
-#endif
-#endif
-#undef min
-#endif
-
-#ifdef max
-#if !defined(_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS)
-#if defined(_LIBCPP_WARNING)
-_LIBCPP_WARNING("macro max is incompatible with C++. Try #define NOMINMAX "
- "before any Windows header. #undefing max")
-#else
-#warning: macro max is incompatible with C++. #undefing max
-#endif
-#endif
-#undef max
-#endif
Index: include/__undef_macros
===================================================================
--- /dev/null
+++ include/__undef_macros
@@ -0,0 +1,34 @@
+// -*- C++ -*-
+//===------------------------ __undef_macros ------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+
+#ifdef min
+#if !defined(_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS)
+#if defined(_LIBCPP_WARNING)
+_LIBCPP_WARNING("macro min is incompatible with C++. Try #define NOMINMAX "
+ "before any Windows header. #undefing min")
+#else
+#warning: macro min is incompatible with C++. #undefing min
+#endif
+#endif
+#undef min
+#endif
+
+#ifdef max
+#if !defined(_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS)
+#if defined(_LIBCPP_WARNING)
+_LIBCPP_WARNING("macro max is incompatible with C++. Try #define NOMINMAX "
+ "before any Windows header. #undefing max")
+#else
+#warning: macro max is incompatible with C++. #undefing max
+#endif
+#endif
+#undef max
+#endif
Index: include/__tree
===================================================================
--- include/__tree
+++ include/__tree
@@ -17,12 +17,16 @@
#include <stdexcept>
#include <algorithm>
-#include <__undef_min_max>
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _Compare, class _Allocator> class __tree;
@@ -2685,4 +2689,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___TREE
Index: include/__threading_support
===================================================================
--- include/__threading_support
+++ include/__threading_support
@@ -30,9 +30,14 @@
#include <Windows.h>
#include <process.h>
#include <fibersapi.h>
-#include <__undef_min_max>
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
#if defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL)
#define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_FUNC_VIS
Index: include/__string
===================================================================
--- include/__string
+++ include/__string
@@ -57,14 +57,18 @@
#include <cstdio> // For EOF.
#include <memory> // for __murmur2_or_cityhash
-#include <__undef_min_max>
-
#include <__debug>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
// char_traits
@@ -870,4 +874,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___STRING
Index: include/__std_stream
===================================================================
--- include/__std_stream
+++ include/__std_stream
@@ -17,12 +17,16 @@
#include <__locale>
#include <cstdio>
-#include <__undef_min_max>
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
static const int __limit = 8;
@@ -355,4 +359,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___STD_STREAM
Index: include/__split_buffer
===================================================================
--- include/__split_buffer
+++ include/__split_buffer
@@ -6,12 +6,16 @@
#include <type_traits>
#include <algorithm>
-#include <__undef_min_max>
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <bool>
@@ -628,7 +632,8 @@
__x.swap(__y);
}
-
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP_SPLIT_BUFFER
Index: include/__mutex_base
===================================================================
--- include/__mutex_base
+++ include/__mutex_base
@@ -15,12 +15,18 @@
#include <chrono>
#include <system_error>
#include <__threading_support>
-#include <__undef_min_max>
+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
#ifndef _LIBCPP_HAS_NO_THREADS
@@ -428,4 +434,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___MUTEX_BASE
Index: include/__hash_table
===================================================================
--- include/__hash_table
+++ include/__hash_table
@@ -20,17 +20,20 @@
#include <utility>
#include <type_traits>
-#include <__undef_min_max>
-
#include <__debug>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
-_LIBCPP_BEGIN_NAMESPACE_STD
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+_LIBCPP_BEGIN_NAMESPACE_STD
+
#ifndef _LIBCPP_CXX03_LANG
template <class _Key, class _Tp>
union __hash_value_type;
@@ -2667,6 +2670,9 @@
}
#endif // _LIBCPP_DEBUG_LEVEL >= 2
+
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP__HASH_TABLE
Index: include/__config
===================================================================
--- include/__config
+++ include/__config
@@ -1201,4 +1201,35 @@
#define _LIBCPP_AVAILABILITY_NO_STREAMS_EXTERN_TEMPLATE
#endif
+#if defined(_LIBCPP_COMPILER_IBM)
+#define _LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO
+#endif
+
+#if defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO)
+# define _LIBCPP_PUSH_MACROS
+# define _LIBCPP_POP_MACROS
+#else
+ // Don't warn about macro conflicts when we can restore them at the
+ // end of the header.
+# ifndef _LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS
+# define _LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS
+# endif
+# if defined(_LIBCPP_COMPILER_MSVC)
+# define _LIBCPP_PUSH_MACROS \
+ __pragma(push_macro("min")) \
+ __pragma(push_macro("max"))
+# define _LIBCPP_POP_MACROS \
+ __pragma(pop_macro("min")) \
+ __pragma(pop_macro("max"))
+# else
+# define _LIBCPP_PUSH_MACROS \
+ _Pragma("push_macro(\"min\")") \
+ _Pragma("push_macro(\"max\")")
+# define _LIBCPP_POP_MACROS \
+ _Pragma("pop_macro(\"min\")") \
+ _Pragma("pop_macro(\"max\")")
+#else
+
+#endif
+
#endif // _LIBCPP_CONFIG
Index: include/__bit_reference
===================================================================
--- include/__bit_reference
+++ include/__bit_reference
@@ -14,12 +14,16 @@
#include <__config>
#include <algorithm>
-#include <__undef_min_max>
-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#if defined(min) || defined(max)
+# include <__undef_macros>
+#endif
+
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0> class __bit_iterator;
@@ -1273,4 +1277,6 @@
_LIBCPP_END_NAMESPACE_STD
+_LIBCPP_POP_MACROS
+
#endif // _LIBCPP___BIT_REFERENCE
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits