diff options
author | David Malcolm <dmalcolm@redhat.com> | 2024-07-24 18:07:53 -0400 |
---|---|---|
committer | Thomas Koenig <tkoenig@gcc.gnu.org> | 2024-07-28 19:05:54 +0200 |
commit | f43be6cc9d84eb8e80c9b01d96a36e5937887253 (patch) | |
tree | d2b4c592f996f0a7f8189d62b72b3cec3af9c7f4 /libcpp | |
parent | 336dceb5dd2d0d8bf235100af4b3c493d8ef591c (diff) | |
download | gcc-f43be6cc9d84eb8e80c9b01d96a36e5937887253.zip gcc-f43be6cc9d84eb8e80c9b01d96a36e5937887253.tar.gz gcc-f43be6cc9d84eb8e80c9b01d96a36e5937887253.tar.bz2 |
json: support std::unique_ptr in array::append and object::set
This patch uses templates to add overloads of json::array::append and
json::object::set taking std::unique_ptr<T> where T is a subclass of
json::value.
Doing so makes it much easier to track memory ownership and enforce
schema validity when constructing non-trivial JSON; using the wrong
kind of JSON value leads to compile-time errors like the following:
error: cannot convert ‘unique_ptr<sarif_message>’ to ‘unique_ptr<sarif_log>’
629 | location_obj->set<sarif_log> ("message", std::move (message_obj));
| ~~~~~~~~~~^~~~~~~~~~~~~
| |
| unique_ptr<sarif_message>
No functional change intended.
gcc/ChangeLog:
* diagnostic-format-json.cc: Define INCLUDE_MEMORY.
* diagnostic-format-sarif.cc: Likewise.
* dumpfile.cc: Likewise.
* gcov.cc: Likewise.
* json.cc: Likewise. Include "make-unique.h".
(selftest::test_formatting): Exercise overloads of
array::append and object::set that use unique_ptr.
* json.h: Require INCLUDE_MEMORY to have been defined.
(json::object::set): Add a template to add a family of overloads
taking a std::unique_ptr<JsonType>
(json::array::append): Likewise.
* optinfo-emit-json.cc: Define INCLUDE_MEMORY.
* optinfo.cc: Likewise.
* timevar.cc: Likewise.
* toplev.cc: Likewise.
* tree-diagnostic-client-data-hooks.cc: Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'libcpp')
0 files changed, 0 insertions, 0 deletions