[RFA 3/5] Use std::string, std::vector in rust-lang.c
Pedro Alves
palves@redhat.com
Thu Sep 22 19:03:00 GMT 2016
On 09/22/2016 06:50 PM, Tom Tromey wrote:
> int num_args = exp->elts[*pos + 1].longconst;
> const char *method;
> - char *name;
> + std::string name;
While we required declaring variables at the top of the
scope in C, in C++ it no longer makes sense. Particularly
if the variable's type as a constructor.
So I think we should move the variable declaration to the
initialization line, to avoid default constructing the variable
and then resetting it afterwards, as the compiler may
not be smart enough to elide that.
>
> - name = concat (TYPE_TAG_NAME (type), "::", method, (char *) NULL);
> - make_cleanup (xfree, name);
> + name = std::string (TYPE_TAG_NAME (type)) + "::" + method;
>
> - char *scopedname = concat (scope, "::", name, (char *) NULL);
> - struct cleanup *cleanup = make_cleanup (xfree, scopedname);
> + std::string scopedname;
> +
> + scopedname = std::string (scope) + "::" + name;
Here too. Throughout the series, really.
Thanks,
Pedro Alves
More information about the Gdb-patches
mailing list