Skip to content

Commit 71d46ca

Browse files
authored
fix: GCC 16 / C++20 build failure with u8 string literals (#1685)
* 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 * style: run clang-format
1 parent 4f7d46f commit 71d46ca

2 files changed

Lines changed: 8 additions & 6 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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,8 @@ 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 =
1997+
reinterpret_cast<const char*>(u8"\u5f0f\uff0c\u8fdb"); // "式,进"
19971998
std::string styled;
19981999
{
19992000
Json::Value v;
@@ -3109,9 +3110,9 @@ JSONTEST_FIXTURE_LOCAL(ReaderTest, strictModeParseNumber) {
31093110
}
31103111

31113112
JSONTEST_FIXTURE_LOCAL(ReaderTest, parseChineseWithOneError) {
3112-
checkParse(R"({ "pr)"
3113-
u8"\u4f50\u85e4" // 佐藤
3114-
R"(erty" :: "value" })",
3113+
checkParse(reinterpret_cast<const char*>(R"({ "pr)"
3114+
u8"\u4f50\u85e4" // 佐藤
3115+
R"(erty" :: "value" })"),
31153116
{{18, 19, "Syntax error: value, object or array expected."}},
31163117
"* Line 1, Column 19\n Syntax error: value, object or array "
31173118
"expected.\n");
@@ -3223,7 +3224,8 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseString) {
32233224
bool ok = reader->parse(doc, doc + std::strlen(doc), &root, &errs);
32243225
JSONTEST_ASSERT(ok);
32253226
JSONTEST_ASSERT(errs.empty());
3226-
JSONTEST_ASSERT_EQUAL(u8"\u8A2a", root[0].asString()); // "訪"
3227+
JSONTEST_ASSERT_EQUAL(reinterpret_cast<const char*>(u8"\u8A2a"),
3228+
root[0].asString()); // "訪"
32273229
}
32283230
{
32293231
char const doc[] = R"([ "\uD801" ])";

0 commit comments

Comments
 (0)