aboutsummaryrefslogtreecommitdiff
path: root/gcc/gcov.cc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2024-07-24 18:07:53 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2024-07-24 18:07:53 -0400
commit2486234b5ae0d71ca7bbdc6e216b4707cd5bef15 (patch)
tree0b6c3b6aad5febd52f4324c7fff5c929f8631663 /gcc/gcov.cc
parent29522bff8f4940a6b4307da0021e257c98eeecea (diff)
downloadgcc-2486234b5ae0d71ca7bbdc6e216b4707cd5bef15.zip
gcc-2486234b5ae0d71ca7bbdc6e216b4707cd5bef15.tar.gz
gcc-2486234b5ae0d71ca7bbdc6e216b4707cd5bef15.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 'gcc/gcov.cc')
-rw-r--r--gcc/gcov.cc1
1 files changed, 1 insertions, 0 deletions
diff --git a/gcc/gcov.cc b/gcc/gcov.cc
index 85fdac4..aa016c6 100644
--- a/gcc/gcov.cc
+++ b/gcc/gcov.cc
@@ -32,6 +32,7 @@ along with Gcov; see the file COPYING3. If not see
#include "config.h"
#define INCLUDE_ALGORITHM
+#define INCLUDE_MEMORY
#define INCLUDE_VECTOR
#define INCLUDE_STRING
#define INCLUDE_MAP