[grade=B] qt: fix C++20 u8string->string conversion in introdialog

fs::path::u8string() returns std::u8string under C++20; the functional
cast to std::string has no matching conversion and clang rejects it,
breaking the triangles-qt build on macOS/Linux/Windows since the Sep-2
auto-load commit (8804740). The Linux/Windows daemon targets compiled
because they exclude introdialog.cpp.

Fix: static pathToUtf8String() reinterprets the char8_t payload (UTF-8
bytes preserved exactly) and both call sites use it. Verified locally:
full triangles-qt target compiles and links (257/257 ninja steps) with
Qt 5.15/gcc. Fixes the build-qt jobs in run 34061376140; daemon,
fuzz, sanitizer, and unit-test jobs were already green on that run.
This commit is contained in:
Krystie
2026-09-06 15:07:22 -07:00
parent f2978ca389
commit b70725da36
+12 -2
View File
@@ -39,6 +39,16 @@ static fs::path qstringToPath(const QString& s)
#endif
}
// Convert fs::path to a UTF-8 std::string. fs::path::u8string() returns
// std::u8string in C++20, which has no implicit conversion to std::string
// (clang/gcc reject the functional cast). Reinterpret the char8_t payload:
// UTF-8 byte values are preserved exactly.
static std::string pathToUtf8String(const fs::path& p)
{
const std::u8string u8 = p.u8string();
return std::string(reinterpret_cast<const char*>(u8.data()), u8.size());
}
IntroDialog::IntroDialog(QWidget *parent) :
QDialog(parent)
{
@@ -233,12 +243,12 @@ bool IntroDialog::pickDataDirectory()
// If the saved path is the default, don't set -datadir (let normal defaults work)
QString defaultDir = QString::fromStdString(
std::string(GetDefaultDataDir().u8string()));
pathToUtf8String(GetDefaultDataDir()));
if (dataDir != defaultDir) {
// Pass the data dir to the daemon as UTF-8 bytes so a non-ASCII path
// on Windows isn't mangled by the ANSI code page (path::string() does
// that). The daemon side uses fs::u8path() to convert back.
mapArgs["-datadir"] = std::string(qstringToPath(dataDir).u8string());
mapArgs["-datadir"] = pathToUtf8String(qstringToPath(dataDir));
}
// Ensure the directory exists