Skip to content

Commit 2fe880d

Browse files
committed
fix: GCC 16 / C++20 build failure with u8 string literals (#1684)
In C++20, the `u8""` string literal prefix was changed to evaluate to `const char8_t[]` instead of `const char[]`. This caused compilation errors when these literals were implicitly converted to `std::string` or passed to functions expecting `const char*`. This commit adds `reinterpret_cast<const char*>` around the `u8` string literals in the test suite to resolve the build errors while maintaining the intended UTF-8 semantics. Additionally, this adds C++20 to the GitHub Actions CMake test matrix to ensure we don't regress on newer standards. Fixes #1684
1 parent 755d0a6 commit 2fe880d

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

.github/workflows/cmake.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
os: [ubuntu-latest, windows-latest, macos-latest]
15-
cxx_standard: [11, 17]
15+
cxx_standard: [11, 17, 20]
1616

1717
steps:
1818
- name: checkout project

src/test_lib_json/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,7 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, StaticString) {
19931993

19941994
JSONTEST_FIXTURE_LOCAL(ValueTest, WideString) {
19951995
// https://github.com/open-source-parsers/jsoncpp/issues/756
1996-
const std::string uni = u8"\u5f0f\uff0c\u8fdb"; // "式,进"
1996+
const std::string uni = reinterpret_cast<const char*>(u8"\u5f0f\uff0c\u8fdb"); // "式,进"
19971997
std::string styled;
19981998
{
19991999
Json::Value v;
@@ -3109,9 +3109,9 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, strictModeParseNumber) {
31093109
}
31103110

31113111
JSONTEST_FIXTURE_LOCAL(ReaderTest, parseChineseWithOneError) {
3112-
checkParse(R"({ "pr)"
3112+
checkParse(reinterpret_cast<const char*>(R"({ "pr)"
31133113
u8"\u4f50\u85e4" // 佐藤
3114-
R"(erty" :: "value" })",
3114+
R"(erty" :: "value" })"),
31153115
{{18, 19, "Syntax error: value, object or array expected."}},
31163116
"* Line 1, Column 19\n Syntax error: value, object or array "
31173117
"expected.\n");
@@ -3223,7 +3223,7 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseString) {
32233223
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
32243224
JSONTEST_ASSERT(ok);
32253225
JSONTEST_ASSERT(errs.empty());
3226-
JSONTEST_ASSERT_EQUAL(u8"\u8A2a", root[0].asString()); // "訪"
3226+
JSONTEST_ASSERT_EQUAL(reinterpret_cast<const char*>(u8"\u8A2a"), root[0].asString()); // "訪"
32273227
}
32283228
{
32293229
char const doc[] = R"([ "\uD801" ])";

0 commit comments

Comments
 (0)