Skip to content

Fix C++11 ABI breakage when compiled with C++17 #1668#1675

Merged
baylesj merged 7 commits intomasterfrom
fix-cxx11-abi-break
Apr 9, 2026
Merged

Fix C++11 ABI breakage when compiled with C++17 #1668#1675
baylesj merged 7 commits intomasterfrom
fix-cxx11-abi-break

Conversation

@baylesj
Copy link
Copy Markdown
Contributor

@baylesj baylesj commented Apr 8, 2026

When JSONCPP_HAS_STRING_VIEW is defined while JsonCpp is built, but not in a consuming library, the
const char* and const String& overloads for operator[], get,
removeMember, and isMember are defined in the header but do not have an implementation, breaking ABI compatibility for projects consuming the library with C++11.

This patchset includes the following changes:

  1. Unconditionally declares and defines the legacy overloads so they are always exported, restoring compatibility

  2. Adds new ABI GitHub Actions targets to ensure that JsonCpp properly links when installed at C++23 and used in a C++11 project, and vice versa

  3. Moves all of the string view methods to be inline and thus header only, which hopefully will make versioning and maintenance slightly easier and usage a little more clear

Fixed #1668

baylesj added 2 commits April 7, 2026 20:39
- Injects `FORCE_JAVASCRIPT_ACTIONS_TO_NODE24=true` in all workflows to
  opt-in to Node.js 24 and suppress the deprecation warnings from
  multiple GitHub Actions.
- Specifies `python-version: '3.x'` for `actions/setup-python@v5` in
  `meson.yml` to fix the missing input warning.
When JSONCPP_HAS_STRING_VIEW was defined, the library dropped the
`const char*` and `const String&` overloads for `operator[]`, `get`,
`removeMember`, and `isMember`, breaking ABI compatibility for projects
consuming the library with C++11.

This change unconditionally declares and defines the legacy overloads
so they are always exported, restoring compatibility.
@baylesj baylesj changed the title Fix cxx11 abi break Fix C++11 ABI breakage when compiled with C++17 (https://github.com/open-source-parsers/jsoncpp/issues/1668) Apr 8, 2026
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 8, 2026

Coverage Report for CI Build 24204236720

Coverage remained the same at 90.093%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 2691
Covered Lines: 2574
Line Coverage: 95.65%
Relevant Branches: 2588
Covered Branches: 2182
Branch Coverage: 84.31%
Branches in Coverage %: Yes
Coverage Strength: 23739.33 hits per line

💛 - Coveralls

baylesj added 4 commits April 8, 2026 12:16
This adds a new GitHub Actions workflow to verify ABI compatibility across C++ standard boundaries. It explicitly tests the scenario where JsonCpp is built with one standard (e.g., C++11) and consumed by an application built with a newer one (e.g., C++23), and vice versa.

To facilitate testing the specific `std::string_view` boundary that is conditionally compiled, a new `stringView` demo application has been added to the `example/` directory and is consumed directly by the CI matrix to ensure standard library symbols link correctly across standard versions, build types (shared/static), and operating systems.
This commit completely eliminates the ABI breakage that occurs across C++ standard boundaries when using `std::string_view`.

Previously, when the library was built with C++17+, CMake would leak `JSONCPP_HAS_STRING_VIEW=1` as a PUBLIC definition. A C++11 consumer would receive this definition, attempt to parse the header, and fail with compiler errors because `std::string_view` is not available in their environment.

Conversely, if the library was built in C++11 (without `string_view` symbols), a C++17 consumer would naturally define `JSONCPP_HAS_STRING_VIEW` based on `__cplusplus` inside `value.h`. The consumer would then call the declared `string_view` methods, resulting in linker errors because the methods weren't compiled into the library.

By moving all `std::string_view` overloads directly into `value.h` as `inline` methods that delegate to the fundamental `const char*, const char*` methods:
1. The consumer's compiler dictates whether the overloads are visible (via `__cplusplus >= 201703L`).
2. The consumer compiles the inline wrappers locally, removing any reliance on the library's exported symbols for `std::string_view`.
3. CMake no longer needs to pollute the consumer's environment with PUBLIC compile definitions.
@baylesj baylesj changed the title Fix C++11 ABI breakage when compiled with C++17 (https://github.com/open-source-parsers/jsoncpp/issues/1668) Fix C++11 ABI breakage when compiled with C++17 #1668 Apr 9, 2026
@baylesj baylesj merged commit c67034e into master Apr 9, 2026
34 checks passed
@baylesj baylesj deleted the fix-cxx11-abi-break branch April 9, 2026 17:37
@baylesj baylesj restored the fix-cxx11-abi-break branch April 9, 2026 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jsoncpp 1.9.7 breaks c++11 support

2 participants