Skip to content

Commit

Permalink
Worked around error C2572: 'std::enable_if': redefinition of default …
Browse files Browse the repository at this point in the history
…argument: parameter 1

All std C++ headers are hidden and replaced with import std.
Some std C headers are added.

Cfr. https://developercommunity.visualstudio.com/t/VS2022-175-Preview-3---Compiler-bug-wit/10256508
  • Loading branch information
matt77hias committed Apr 7, 2024
1 parent b988546 commit 3da01e3
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 98 deletions.
8 changes: 5 additions & 3 deletions include/fmt/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
#ifndef FMT_ARGS_H_
#define FMT_ARGS_H_

#include <functional> // std::reference_wrapper
#include <memory> // std::unique_ptr
#include <vector>
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//#include <functional> // std::reference_wrapper
//#include <memory> // std::unique_ptr
//#include <vector>
// DIVERGENCE END

#include "format.h" // std_string_view

Expand Down
14 changes: 9 additions & 5 deletions include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
#ifndef FMT_BASE_H_
#define FMT_BASE_H_

#include <limits.h> // CHAR_BIT
#include <stdio.h> // FILE
#include <string.h> // strlen
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//#include <limits.h> // CHAR_BIT
//#include <stdio.h> // FILE
//#include <string.h> // strlen
// DIVERGENCE END

// <cstddef> is also included transitively from <type_traits>.
#include <cstddef> // std::byte
#include <type_traits> // std::enable_if
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//#include <cstddef> // std::byte
//#include <type_traits> // std::enable_if
// DIVERGENCE END

// The fmt library version in the form major * 10000 + minor * 100 + patch.
#define FMT_VERSION 100202
Expand Down
20 changes: 11 additions & 9 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
#ifndef FMT_CHRONO_H_
#define FMT_CHRONO_H_

#include <algorithm>
#include <chrono>
#include <cmath> // std::isfinite
#include <cstring> // std::memcpy
#include <ctime>
#include <iterator>
#include <locale>
#include <ostream>
#include <type_traits>
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//#include <algorithm>
//#include <chrono>
//#include <cmath> // std::isfinite
//#include <cstring> // std::memcpy
//#include <ctime>
//#include <iterator>
//#include <locale>
//#include <ostream>
//#include <type_traits>
// DIVERGENCE END

#include "format.h"

Expand Down
4 changes: 3 additions & 1 deletion include/fmt/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#ifndef FMT_COMPILE_H_
#define FMT_COMPILE_H_

#include <iterator> // std::back_inserter
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//#include <iterator> // std::back_inserter
// DIVERGENCE END

#include "format.h"

Expand Down
16 changes: 10 additions & 6 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
#ifndef FMT_FORMAT_INL_H_
#define FMT_FORMAT_INL_H_

#include <algorithm>
#include <cerrno> // errno
#include <climits>
#include <cmath>
#include <exception>
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//#include <algorithm>
//#include <cerrno> // errno
//#include <climits>
//#include <cmath>
//#include <exception>
// DIVERGENCE END

#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
# include <locale>
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//# include <locale>
// DIVERGENCE END
#endif

#if defined(_WIN32) && !defined(FMT_USE_WRITE_CONSOLE)
Expand Down
32 changes: 21 additions & 11 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,40 @@
# define FMT_REMOVE_TRANSITIVE_INCLUDES
#endif

#include <cmath> // std::signbit
#include <cstdint> // uint32_t
#include <cstring> // std::memcpy
#include <initializer_list> // std::initializer_list
#include <limits> // std::numeric_limits
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//#include <cmath> // std::signbit
//#include <cstdint> // uint32_t
//#include <cstring> // std::memcpy
//#include <initializer_list> // std::initializer_list
//#include <limits> // std::numeric_limits
// DIVERGENCE END
#if defined(__GLIBCXX__) && !defined(_GLIBCXX_USE_DUAL_ABI)
// Workaround for pre gcc 5 libstdc++.
# include <memory> // std::allocator_traits
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//# include <memory> // std::allocator_traits
// DIVERGENCE END
#endif
#include <stdexcept> // std::runtime_error
#include <string> // std::string
#include <system_error> // std::system_error
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//#include <stdexcept> // std::runtime_error
//#include <string> // std::string
//#include <system_error> // std::system_error
// DIVERGENCE END

#include "base.h"

// Checking FMT_CPLUSPLUS for warning suppression in MSVC.
#if FMT_HAS_INCLUDE(<bit>) && FMT_CPLUSPLUS > 201703L
# include <bit> // std::bit_cast
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//# include <bit> // std::bit_cast
// DIVERGENCE END
#endif

// libc++ supports string_view in pre-c++17.
#if FMT_HAS_INCLUDE(<string_view>) && \
(FMT_CPLUSPLUS >= 201703L || defined(_LIBCPP_VERSION))
# include <string_view>
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//# include <string_view>
// DIVERGENCE END
# define FMT_USE_STRING_VIEW
#endif

Expand Down
10 changes: 6 additions & 4 deletions include/fmt/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
#ifndef FMT_OS_H_
#define FMT_OS_H_

#include <cerrno>
#include <cstddef>
#include <cstdio>
#include <system_error> // std::system_error
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//#include <cerrno>
//#include <cstddef>
//#include <cstdio>
//#include <system_error> // std::system_error
// DIVERGENCE END

#include "format.h"

Expand Down
4 changes: 3 additions & 1 deletion include/fmt/ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#ifndef FMT_OSTREAM_H_
#define FMT_OSTREAM_H_

#include <fstream> // std::filebuf
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//#include <fstream> // std::filebuf
// DIVERGENCE END

#ifdef _WIN32
# ifdef __GLIBCXX__
Expand Down
6 changes: 4 additions & 2 deletions include/fmt/printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
#ifndef FMT_PRINTF_H_
#define FMT_PRINTF_H_

#include <algorithm> // std::max
#include <limits> // std::numeric_limits
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//#include <algorithm> // std::max
//#include <limits> // std::numeric_limits
// DIVERGENCE END

#include "format.h"

Expand Down
10 changes: 6 additions & 4 deletions include/fmt/ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
#ifndef FMT_RANGES_H_
#define FMT_RANGES_H_

#include <initializer_list>
#include <iterator>
#include <tuple>
#include <type_traits>
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//#include <initializer_list>
//#include <iterator>
//#include <tuple>
//#include <type_traits>
// DIVERGENCE END

#include "format.h"

Expand Down
48 changes: 31 additions & 17 deletions include/fmt/std.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,57 @@
#ifndef FMT_STD_H_
#define FMT_STD_H_

#include <atomic>
#include <bitset>
#include <complex>
#include <cstdlib>
#include <exception>
#include <memory>
#include <thread>
#include <type_traits>
#include <typeinfo>
#include <utility>
#include <vector>
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//#include <atomic>
//#include <bitset>
//#include <complex>
//#include <cstdlib>
//#include <exception>
//#include <memory>
//#include <thread>
//#include <type_traits>
//#include <typeinfo>
//#include <utility>
//#include <vector>
// DIVERGENCE END

#include "format.h"
#include "ostream.h"

#if FMT_HAS_INCLUDE(<version>)
# include <version>
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//# include <version>
// DIVERGENCE END
#endif
// Checking FMT_CPLUSPLUS for warning suppression in MSVC.
#if FMT_CPLUSPLUS >= 201703L
# if FMT_HAS_INCLUDE(<filesystem>)
# include <filesystem>
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//# include <filesystem>
// DIVERGENCE END
# endif
# if FMT_HAS_INCLUDE(<variant>)
# include <variant>
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//# include <variant>
// DIVERGENCE END
# endif
# if FMT_HAS_INCLUDE(<optional>)
# include <optional>
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//# include <optional>
// DIVERGENCE END
# endif
#endif

#if FMT_HAS_INCLUDE(<expected>) && FMT_CPLUSPLUS > 202002L
# include <expected>
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//# include <expected>
// DIVERGENCE END
#endif

#if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE(<source_location>)
# include <source_location>
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//# include <source_location>
// DIVERGENCE END
#endif

// GCC 4 does not support FMT_HAS_INCLUDE.
Expand Down
8 changes: 6 additions & 2 deletions include/fmt/xchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
#ifndef FMT_XCHAR_H_
#define FMT_XCHAR_H_

#include <cwchar>
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//#include <cwchar>
// DIVERGENCE END

#include "color.h"
#include "format.h"
#include "ranges.h"

#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
# include <locale>
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//# include <locale>
// DIVERGENCE END
#endif

FMT_BEGIN_NAMESPACE
Expand Down
77 changes: 45 additions & 32 deletions src/fmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,47 @@ module;

// Put all implementation-provided headers into the global module fragment
// to prevent attachment to this module.
#include <algorithm>
#include <cerrno>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <exception>
#include <filesystem>
#include <fstream>
#include <functional>
#include <iterator>
#include <limits>
#include <locale>
#include <memory>
#include <optional>
#include <ostream>
#include <stdexcept>
#include <string>
#include <string_view>
#include <system_error>
#include <thread>
#include <type_traits>
#include <typeinfo>
#include <utility>
#include <variant>
#include <vector>
#include <version>
// DIVERGENCE BEGIN - Worked around std imports and includes mixing
//#include <algorithm>
//#include <cerrno>
//#include <chrono>
//#include <climits>
//#include <cmath>
//#include <cstddef>
//#include <cstdint>
//#include <cstdio>
//#include <cstdlib>
//#include <cstring>
//#include <ctime>
//#include <exception>
//#include <filesystem>
//#include <fstream>
//#include <functional>
//#include <iterator>
//#include <limits>
//#include <locale>
//#include <memory>
//#include <optional>
//#include <ostream>
//#include <stdexcept>
//#include <string>
//#include <string_view>
//#include <system_error>
//#include <thread>
//#include <type_traits>
//#include <typeinfo>
//#include <utility>
//#include <variant>
//#include <vector>
//#include <version>
// DIVERGENCE END

// DIVERGENCE BEGIN - Worked around std imports and includes mixing
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>
// DIVERGENCE END

#if __has_include(<cxxabi.h>)
# include <cxxabi.h>
Expand Down Expand Up @@ -70,6 +79,10 @@ module;

export module fmt;

// DIVERGENCE BEGIN - Worked around std imports and includes mixing
import std;
// DIVERGENCE END

#define FMT_EXPORT export
#define FMT_BEGIN_EXPORT export {
#define FMT_END_EXPORT }
Expand Down
Loading

0 comments on commit 3da01e3

Please sign in to comment.