Fix windows libc++ fs::path fstream compile errors
As reported by hebasto in https://github.com/bitcoin/bitcoin/issues/33545, newer libc++ versions implementing https://wg21.link/lwg3430 will no longer implicitly convert `fs::path` objects to `std::filesystem::path` objects when constructing `std::ifstream` and `std::ofstream` types. This is not a problem in Unix systems since `fs::path` objects use `std::string` as their native string type, but it causes compile errors on Windows which use `std::wstring` as their string type, since `fstream`s can't be constructed from `wstring`s. Fix the windows libc++ compile errors by adding a new `fs::path::std_path()` method and using it construct `fstream`s more portably. Additionally, delete `fs::path`'s implicit `native_string` conversion so these errors will not go undetected in the future, even though there is not currently a CI job testing Windows libc++ builds.
This commit is contained in:
1 parent
a33bd767a3
commit
b0113afd44
13 files changed
+37
-27
No files matched your search
+2
-2
@@ -102,7 +102,7 @@ bool IsBDBFile(const fs::path& path)
|
||||
if (ec) LogWarning("Error reading file_size: %s [%s]", ec.message(), fs::PathToString(path));
|
||||
if (size < 4096) return false;
|
||||
|
||||
std::ifstream file{path, std::ios::binary};
|
||||
std::ifstream file{path.std_path(), std::ios::binary};
|
||||
if (!file.is_open()) return false;
|
||||
|
||||
file.seekg(12, std::ios::beg); // Magic bytes start at offset 12
|
||||
@@ -126,7 +126,7 @@ bool IsSQLiteFile(const fs::path& path)
|
||||
if (ec) LogWarning("Error reading file_size: %s [%s]", ec.message(), fs::PathToString(path));
|
||||
if (size < 512) return false;
|
||||
|
||||
std::ifstream file{path, std::ios::binary};
|
||||
std::ifstream file{path.std_path(), std::ios::binary};
|
||||
if (!file.is_open()) return false;
|
||||
|
||||
// Magic is at beginning and is 16 bytes long
|
||||
|
||||
+1
-1
@@ -134,7 +134,7 @@ bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs::
|
||||
error = strprintf(_("Dump file %s does not exist."), fs::PathToString(dump_path));
|
||||
return false;
|
||||
}
|
||||
std::ifstream dump_file{dump_path};
|
||||
std::ifstream dump_file{dump_path.std_path()};
|
||||
|
||||
// Compute the checksum
|
||||
HashWriter hasher{};
|
||||
|
||||
@@ -36,7 +36,7 @@ InitWalletDirTestingSetup::InitWalletDirTestingSetup(const ChainType chainType)
|
||||
fs::create_directories(m_walletdir_path_cases["default"]);
|
||||
fs::create_directories(m_walletdir_path_cases["custom"]);
|
||||
fs::create_directories(m_walletdir_path_cases["relative"]);
|
||||
std::ofstream f{m_walletdir_path_cases["file"]};
|
||||
std::ofstream f{m_walletdir_path_cases["file"].std_path()};
|
||||
f.close();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user