aboutsummaryrefslogtreecommitdiff
path: root/libcpp/include/line-map.h
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2022-07-27 10:15:41 -0700
committerIan Lance Taylor <iant@golang.org>2022-07-27 10:15:41 -0700
commit9f62ed218fa656607740b386c0caa03e65dcd283 (patch)
tree6bde49bc5e4c4241266b108e4277baef4b85535d /libcpp/include/line-map.h
parent71e955da39cea0ebffcfee3432effa622d14ca99 (diff)
parent5eb9f117a361538834b9740d59219911680717d1 (diff)
downloadgcc-9f62ed218fa656607740b386c0caa03e65dcd283.zip
gcc-9f62ed218fa656607740b386c0caa03e65dcd283.tar.gz
gcc-9f62ed218fa656607740b386c0caa03e65dcd283.tar.bz2
Merge from trunk revision 5eb9f117a361538834b9740d59219911680717d1.
Diffstat (limited to 'libcpp/include/line-map.h')
-rw-r--r--libcpp/include/line-map.h55
1 files changed, 43 insertions, 12 deletions
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index 8033572..9bdd5b9 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -22,6 +22,8 @@ along with this program; see the file COPYING3. If not see
#ifndef LIBCPP_LINE_MAP_H
#define LIBCPP_LINE_MAP_H
+#include <utility>
+
#ifndef GTY
#define GTY(x) /* nothing */
#endif
@@ -1836,15 +1838,37 @@ class label_text
{
public:
label_text ()
- : m_buffer (NULL), m_caller_owned (false)
+ : m_buffer (NULL), m_owned (false)
{}
- void maybe_free ()
+ ~label_text ()
{
- if (m_caller_owned)
+ if (m_owned)
free (m_buffer);
}
+ /* Move ctor. */
+ label_text (label_text &&other)
+ : m_buffer (other.m_buffer), m_owned (other.m_owned)
+ {
+ other.release ();
+ }
+
+ /* Move assignment. */
+ label_text & operator= (label_text &&other)
+ {
+ if (m_owned)
+ free (m_buffer);
+ m_buffer = other.m_buffer;
+ m_owned = other.m_owned;
+ other.release ();
+ return *this;
+ }
+
+ /* Delete the copy ctor and copy-assignment operator. */
+ label_text (const label_text &) = delete;
+ label_text & operator= (const label_text &) = delete;
+
/* Create a label_text instance that borrows BUFFER from a
longer-lived owner. */
static label_text borrow (const char *buffer)
@@ -1858,21 +1882,28 @@ public:
return label_text (buffer, true);
}
- /* Take ownership of the buffer, copying if necessary. */
- char *take_or_copy ()
+ void release ()
{
- if (m_caller_owned)
- return m_buffer;
- else
- return xstrdup (m_buffer);
+ m_buffer = NULL;
+ m_owned = false;
}
- char *m_buffer;
- bool m_caller_owned;
+ const char *get () const
+ {
+ return m_buffer;
+ }
+
+ bool is_owner () const
+ {
+ return m_owned;
+ }
private:
+ char *m_buffer;
+ bool m_owned;
+
label_text (char *buffer, bool owned)
- : m_buffer (buffer), m_caller_owned (owned)
+ : m_buffer (buffer), m_owned (owned)
{}
};