+2019-12-09 David Malcolm <dmalcolm@redhat.com>
+
+ * gcc-rich-location.c
+ (maybe_range_label_for_tree_type_mismatch::get_text): Replace
+ label_text ctor call with label_text::borrow.
+ * gcc-rich-location.h (text_range_label::get_text): Replace
+ label_text ctor called with false with label_text::borrow.
+
2019-12-09 David Malcolm <dmalcolm@redhat.com>
* diagnostic-show-locus.c (diagnostic_show_locus): Remove initial
+2019-12-09 David Malcolm <dmalcolm@redhat.com>
+
+ * c-format.c (range_label_for_format_type_mismatch::get_text):
+ Replace label_text ctor called with true with label_text::take.
+
2019-12-09 David Malcolm <dmalcolm@redhat.com>
* c-format.c (selftest::test_type_mismatch_range_labels): Remove
char *result = concat (text.m_buffer, p, NULL);
text.maybe_free ();
- return label_text (result, true);
+ return label_text::take (result);
}
private:
+2019-12-09 David Malcolm <dmalcolm@redhat.com>
+
+ * c-objc-common.c (range_label_for_type_mismatch::get_text):
+ Replace label_text ctor calls.
+
2019-12-04 Joseph Myers <joseph@codesourcery.com>
PR c/36941
range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const
{
if (m_labelled_type == NULL_TREE)
- return label_text (NULL, false);
+ return label_text::borrow (NULL);
c_pretty_printer cpp;
bool quoted = false;
print_type (&cpp, m_labelled_type, "ed);
- return label_text (xstrdup (pp_formatted_text (&cpp)), true);
+ return label_text::take (xstrdup (pp_formatted_text (&cpp)));
}
+2019-12-09 David Malcolm <dmalcolm@redhat.com>
+
+ * error.c (range_label_for_type_mismatch::get_text): Replace
+ label_text ctor calls with label_text::borrow.
+
2019-12-09 Paolo Carlini <paolo.carlini@oracle.com>
* typeck.c (check_for_casting_away_constness): Add location_t
range_label_for_type_mismatch::get_text (unsigned /*range_idx*/) const
{
if (m_labelled_type == NULL_TREE)
- return label_text (NULL, false);
+ return label_text::borrow (NULL);
const bool verbose = false;
const bool show_color = false;
/* Both of the above return GC-allocated buffers, so the caller mustn't
free them. */
- return label_text (const_cast <char *> (result), false);
+ return label_text::borrow (result);
}
{
if (m_expr == NULL_TREE
|| !EXPR_P (m_expr))
- return label_text (NULL, false);
+ return label_text::borrow (NULL);
tree expr_type = TREE_TYPE (m_expr);
tree other_type = NULL_TREE;
label_text get_text (unsigned /*range_idx*/) const FINAL OVERRIDE
{
- return label_text (const_cast <char *> (m_text), false);
+ return label_text::borrow (m_text);
}
private:
+2019-12-09 David Malcolm <dmalcolm@redhat.com>
+
+ * include/line-map.h (label_text::label_text): Make private.
+ (label_text::borrow): New.
+ (label_text::take): New.
+ (label_text::take_or_copy): New.
+
2019-12-09 Lewis Hyatt <lhyatt@gmail.com>
PR preprocessor/49973
: m_buffer (NULL), m_caller_owned (false)
{}
- label_text (char *buffer, bool caller_owned)
- : m_buffer (buffer), m_caller_owned (caller_owned)
- {}
-
void maybe_free ()
{
if (m_caller_owned)
free (m_buffer);
}
+ /* Create a label_text instance that borrows BUFFER from a
+ longer-lived owner. */
+ static label_text borrow (const char *buffer)
+ {
+ return label_text (const_cast <char *> (buffer), false);
+ }
+
+ /* Create a label_text instance that takes ownership of BUFFER. */
+ static label_text take (char *buffer)
+ {
+ return label_text (buffer, true);
+ }
+
+ /* Take ownership of the buffer, copying if necessary. */
+ char *take_or_copy ()
+ {
+ if (m_caller_owned)
+ return m_buffer;
+ else
+ return xstrdup (m_buffer);
+ }
+
char *m_buffer;
bool m_caller_owned;
+
+private:
+ label_text (char *buffer, bool owned)
+ : m_buffer (buffer), m_caller_owned (owned)
+ {}
};
/* Abstract base class for labelling a range within a rich_location