This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA 3/5] Use std::string, std::vector in rust-lang.c


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]