Skip to content

Commit 573cdb2

Browse files
DimitryAndricnunotexbsd
authored andcommitted
emulators/dosbox-x: Fix build with libc++ 19
As noted in the libc++ 19 release notes [1], std::char_traits<> is now only provided for char, char8_t, char16_t, char32_t and wchar_t, and any instantiation for other types will fail. This causes emulators/dosbox-x to fail to compile with clang 19 and libc++ 19, resulting in errors similar to: /usr/include/c++/v1/string:820:42: error: implicit instantiation of undefined template 'std::char_traits<unsigned short>' 820 | static_assert(is_same<_CharT, typename traits_type::char_type>::value, | ^ dos_programs.cpp:7692:17: note: in instantiation of template class 'std::basic_string<unsigned short>' requested here 7692 | test_string dst; | ^ /usr/include/c++/v1/__fwd/string.h:23:29: note: template is declared here 23 | struct _LIBCPP_TEMPLATE_VIS char_traits; | ^ dos_programs.cpp:8893:14: warning: variable 'open' set but not used [-Wunused-but-set-variable] 8893 | bool open=false; | ^ This can be fixed by using char16_t for the 'test_char_t` type, and by adding a few inline wrappers to perform the required casting. [1] https://libcxx.llvm.org/ReleaseNotes/19.html#deprecations-and-removals PR: 282386 MFH: 2024Q4
1 parent 9bd8fc2 commit 573cdb2

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Fix build with clang 19
2+
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=282386
3+
4+
--- src/dos/dos_programs.cpp.orig 2024-10-02 06:16:36 UTC
5+
+++ src/dos/dos_programs.cpp
6+
@@ -81,7 +81,7 @@ host_cnv_char_t *CodePageGuestToHost(const char *s);
7+
#endif
8+
#ifdef C_ICONV
9+
#include "iconvpp.hpp"
10+
-typedef uint16_t test_char_t;
11+
+typedef char16_t test_char_t;
12+
typedef std::basic_string<test_char_t> test_string;
13+
typedef std::basic_string<char> test_char;
14+
#endif
15+
@@ -102,6 +102,9 @@ bool CodePageHostToGuestUTF8(char *d/*CROSS_LEN*/,cons
16+
bool qmount = false;
17+
bool nowarn = false;
18+
bool CodePageHostToGuestUTF8(char *d/*CROSS_LEN*/,const char *s/*CROSS_LEN*/), CodePageHostToGuestUTF16(char *d/*CROSS_LEN*/,const uint16_t *s/*CROSS_LEN*/);
19+
+inline bool CodePageHostToGuestUTF16(char *d/*CROSS_LEN*/,const char16_t *s/*CROSS_LEN*/) {
20+
+ return CodePageHostToGuestUTF16(d, reinterpret_cast<const uint16_t *>(s));
21+
+}
22+
extern bool systemmessagebox(char const * aTitle, char const * aMessage, char const * aDialogType, char const * aIconType, int aDefaultButton);
23+
extern bool addovl, addipx, addne2k, prepared, inshell, usecon, uao, loadlang, morelen, mountfro[26], mountiro[26], resetcolor, staycolors, printfont, notrycp, internal_program;
24+
extern bool clear_screen(), OpenGL_using(void), DOS_SetAnsiAttr(uint8_t attr), isDBCSCP();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Fix build with clang 19
2+
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=282386
3+
4+
--- src/dos/drive_iso.cpp.orig 2024-10-02 06:16:36 UTC
5+
+++ src/dos/drive_iso.cpp
6+
@@ -40,6 +40,10 @@ extern bool CodePageHostToGuestUTF16(char *d/*CROSS_LE
7+
extern bool gbk, isDBCSCP(), isKanji1_gbk(uint8_t chr), shiftjis_lead_byte(int c);
8+
extern bool filename_not_8x3(const char *n), filename_not_strict_8x3(const char *n);
9+
extern bool CodePageHostToGuestUTF16(char *d/*CROSS_LEN*/,const uint16_t *s/*CROSS_LEN*/);
10+
+inline bool CodePageHostToGuestUTF16(uint8_t *d/*CROSS_LEN*/,const uint8_t *s/*CROSS_LEN*/) {
11+
+ std::u16string u16s(reinterpret_cast<const char16_t *>(s));
12+
+ return CodePageHostToGuestUTF16(reinterpret_cast<char *>(d), reinterpret_cast<const uint16_t *>(u16s.c_str()));
13+
+}
14+
15+
using namespace std;
16+
17+
@@ -1762,7 +1766,7 @@ int isoDrive::readDirEntry(isoDirEntry* de, const uint
18+
// The string is big Endian UCS-16, convert to host Endian UCS-16
19+
for (size_t i=0;((const uint16_t*)de->ident)[i] != 0;i++) ((uint16_t*)de->ident)[i] = be16toh(((uint16_t*)de->ident)[i]);
20+
// finally, convert from UCS-16 to local code page, using C++ string construction to make a copy first
21+
- CodePageHostToGuestUTF16((char*)de->ident,std::basic_string<uint16_t>((const uint16_t*)de->ident).c_str());
22+
+ CodePageHostToGuestUTF16(de->ident, de->ident);
23+
}
24+
}
25+
} else {
26+
@@ -1784,7 +1788,7 @@ int isoDrive::readDirEntry(isoDirEntry* de, const uint
27+
// The string is big Endian UCS-16, convert to host Endian UCS-16
28+
for (size_t i=0;((const uint16_t*)de->ident)[i] != 0;i++) ((uint16_t*)de->ident)[i] = be16toh(((uint16_t*)de->ident)[i]);
29+
// finally, convert from UCS-16 to local code page, using C++ string construction to make a copy first
30+
- CodePageHostToGuestUTF16((char*)de->ident,std::basic_string<uint16_t>((const uint16_t*)de->ident).c_str());
31+
+ CodePageHostToGuestUTF16(de->ident, de->ident);
32+
}
33+
else {
34+
// remove any file version identifiers as there are some cdroms that don't have them

0 commit comments

Comments
 (0)