Skip to content

Commit

Permalink
partial bitcoin#24169: Add --enable-c++20 option
Browse files Browse the repository at this point in the history
excludes:
- fae6790
  • Loading branch information
kwvg committed Jul 21, 2024
1 parent 235e7b5 commit df18ed9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
8 changes: 4 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ AC_ARG_ENABLE([c++20],
[use_cxx20=$enableval],
[use_cxx20=no])

dnl Require C++17 or C++20 compiler (no GNU extensions)
if test "x$use_cxx20" = xyes; then
AX_CXX_COMPILE_STDCXX([20], [noext], [mandatory])
else
dnl Require C++17 compiler (no GNU extensions)
if test "$use_cxx20" = "no"; then
AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory])
else
AX_CXX_COMPILE_STDCXX([20], [noext], [mandatory])
fi

dnl Check if -latomic is required for <std::atomic>
Expand Down
18 changes: 16 additions & 2 deletions src/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,26 @@ class path : public std::filesystem::path
// Disallow std::string conversion method to avoid locale-dependent encoding on windows.
std::string string() const = delete;

std::string u8string() const
{
const auto& utf8_str{std::filesystem::path::u8string()};
// utf8_str might either be std::string (C++17) or std::u8string
// (C++20). Convert both to std::string. This method can be removed
// after switching to C++20.
return std::string{utf8_str.begin(), utf8_str.end()};
}

// Required for path overloads in <fstream>.
// See https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=96e0367ead5d8dcac3bec2865582e76e2fbab190
path& make_preferred() { std::filesystem::path::make_preferred(); return *this; }
path filename() const { return std::filesystem::path::filename(); }
};

static inline path u8path(const std::string& utf8_str)
{
return std::filesystem::u8path(utf8_str);
}

// Disallow implicit std::string conversion for absolute to avoid
// locale-dependent encoding on windows.
static inline path absolute(const path& p)
Expand Down Expand Up @@ -116,8 +130,8 @@ static inline std::string PathToString(const path& path)
// use here, because these methods encode the path using C++'s narrow
// multibyte encoding, which on Windows corresponds to the current "code
// page", which is unpredictable and typically not able to represent all
// valid paths. So std::filesystem::path::u8string() and
// std::filesystem::u8path() functions are used instead on Windows. On
// valid paths. So fs::path::u8string() and
// fs::u8path() functions are used instead on Windows. On
// POSIX, u8string/u8path functions are not safe to use because paths are
// not always valid UTF-8, so plain string methods which do not transform
// the path there are used.
Expand Down
2 changes: 1 addition & 1 deletion src/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static void Repeat(CScheduler& s, CScheduler::Function f, std::chrono::milliseco

void CScheduler::scheduleEvery(CScheduler::Function f, std::chrono::milliseconds delta)
{
scheduleFromNow([=] { Repeat(*this, f, delta); }, delta);
scheduleFromNow([this, f, delta] { Repeat(*this, f, delta); }, delta);
}

size_t CScheduler::getQueueInfo(std::chrono::system_clock::time_point& first,
Expand Down

0 comments on commit df18ed9

Please sign in to comment.