aboutsummaryrefslogtreecommitdiff
path: root/gdb/c-exp.y
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2022-01-24 20:00:46 -0500
committerSimon Marchi <simon.marchi@polymtl.ca>2022-01-26 10:01:40 -0500
commit5d10a2041eb843fd321ce1d850cf3e0df7648bc7 (patch)
treea1bd00ecbd780dc194da8d44b713b09f10446c0a /gdb/c-exp.y
parentb583c328e71369f90f4042ac7973ce9edfdb44b3 (diff)
downloadgdb-5d10a2041eb843fd321ce1d850cf3e0df7648bc7.zip
gdb-5d10a2041eb843fd321ce1d850cf3e0df7648bc7.tar.gz
gdb-5d10a2041eb843fd321ce1d850cf3e0df7648bc7.tar.bz2
gdb: add string_file::release method
A common pattern for string_file is to want to move out the internal string buffer, because it is the result of the computation that we want to return. It is the reason why string_file::string returns a non-const reference, as explained in the comment. I think it would make sense to have a dedicated method for that instead and make string_file::string return a const reference. This allows removing the explicit std::move in the typical case. Note that compile_program::compute was missing a move, meaning that the resulting string was copied. With the new version, it's not possible to forget to move. Change-Id: Ieaefa35b73daa7930b2f3a26988b6e3b4121bb79
Diffstat (limited to 'gdb/c-exp.y')
-rw-r--r--gdb/c-exp.y6
1 files changed, 3 insertions, 3 deletions
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 85499de..464ed44 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -1780,11 +1780,11 @@ oper: OPERATOR NEW
| OPERATOR OBJC_LBRAC ']'
{ $$ = operator_stoken ("[]"); }
| OPERATOR conversion_type_id
- { string_file buf;
-
+ {
+ string_file buf;
c_print_type ($2, NULL, &buf, -1, 0,
&type_print_raw_options);
- std::string name = std::move (buf.string ());
+ std::string name = buf.release ();
/* This also needs canonicalization. */
gdb::unique_xmalloc_ptr<char> canon