Commit 3b927e4
committed
fix: inline std::string_view methods to prevent ABI breaks
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.1 parent 60149bc commit 3b927e4
3 files changed
Lines changed: 31 additions & 76 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
357 | 357 | | |
358 | 358 | | |
359 | 359 | | |
360 | | - | |
| 360 | + | |
| 361 | + | |
361 | 362 | | |
362 | 363 | | |
363 | 364 | | |
| |||
405 | 406 | | |
406 | 407 | | |
407 | 408 | | |
408 | | - | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
409 | 417 | | |
410 | 418 | | |
411 | 419 | | |
| |||
496 | 504 | | |
497 | 505 | | |
498 | 506 | | |
499 | | - | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
500 | 510 | | |
501 | 511 | | |
502 | 512 | | |
503 | | - | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
504 | 519 | | |
505 | 520 | | |
506 | 521 | | |
| |||
532 | 547 | | |
533 | 548 | | |
534 | 549 | | |
535 | | - | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
536 | 553 | | |
537 | 554 | | |
538 | 555 | | |
| |||
586 | 603 | | |
587 | 604 | | |
588 | 605 | | |
589 | | - | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
590 | 609 | | |
591 | 610 | | |
592 | 611 | | |
| |||
599 | 618 | | |
600 | 619 | | |
601 | 620 | | |
602 | | - | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
603 | 624 | | |
604 | 625 | | |
605 | 626 | | |
| |||
618 | 639 | | |
619 | 640 | | |
620 | 641 | | |
621 | | - | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
622 | 645 | | |
623 | 646 | | |
624 | 647 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | 134 | | |
138 | 135 | | |
139 | 136 | | |
| |||
168 | 165 | | |
169 | 166 | | |
170 | 167 | | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | 168 | | |
175 | 169 | | |
176 | 170 | | |
| |||
198 | 192 | | |
199 | 193 | | |
200 | 194 | | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | 195 | | |
205 | 196 | | |
206 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
441 | 441 | | |
442 | 442 | | |
443 | 443 | | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | 444 | | |
452 | 445 | | |
453 | 446 | | |
| |||
656 | 649 | | |
657 | 650 | | |
658 | 651 | | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | | - | |
666 | | - | |
667 | | - | |
668 | | - | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
673 | 652 | | |
674 | 653 | | |
675 | 654 | | |
| |||
1190 | 1169 | | |
1191 | 1170 | | |
1192 | 1171 | | |
1193 | | - | |
1194 | | - | |
1195 | | - | |
1196 | | - | |
1197 | | - | |
1198 | | - | |
1199 | | - | |
1200 | | - | |
1201 | | - | |
1202 | | - | |
1203 | | - | |
1204 | 1172 | | |
1205 | 1173 | | |
1206 | 1174 | | |
| |||
1260 | 1228 | | |
1261 | 1229 | | |
1262 | 1230 | | |
1263 | | - | |
1264 | | - | |
1265 | | - | |
1266 | | - | |
1267 | | - | |
1268 | 1231 | | |
1269 | 1232 | | |
1270 | 1233 | | |
| |||
1286 | 1249 | | |
1287 | 1250 | | |
1288 | 1251 | | |
1289 | | - | |
1290 | | - | |
1291 | | - | |
1292 | | - | |
1293 | | - | |
1294 | 1252 | | |
1295 | 1253 | | |
1296 | 1254 | | |
1297 | 1255 | | |
1298 | 1256 | | |
1299 | 1257 | | |
1300 | 1258 | | |
1301 | | - | |
1302 | | - | |
1303 | | - | |
1304 | | - | |
1305 | | - | |
1306 | | - | |
1307 | | - | |
1308 | | - | |
1309 | | - | |
1310 | | - | |
1311 | | - | |
1312 | | - | |
1313 | 1259 | | |
1314 | 1260 | | |
1315 | 1261 | | |
| |||
1349 | 1295 | | |
1350 | 1296 | | |
1351 | 1297 | | |
1352 | | - | |
1353 | | - | |
1354 | | - | |
1355 | | - | |
1356 | | - | |
1357 | 1298 | | |
1358 | 1299 | | |
1359 | 1300 | | |
| |||
0 commit comments