This is the mail archive of the gdb-patches@sources.redhat.com 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] handling of 'operator' in cp_find_first_component


On Fri, Apr 18, 2003 at 12:17:54PM -0700, David Carlton wrote:
> The function cp_find_first_component assumes that the string
> 'operator' as part of an operator name can only occur at the start of
> a component.  Unfortunately, this isn't true: I've recently run into
> situations where there's a templated function whose name demangles to
> something like
> 
>   int operator<< <int>(char)
> 
> In particular, the return type is part of the demangled name (I'm not
> entirely sure why, but that's a separate issue), so 'operator' occurs
> after a space.
> 
> This patch modifies cp_find_first_component to accept that; it looks
> for the string 'operator' either at the beginning of a name or after a
> few other characters.  I've also added some test cases for this.
> 
> Tested on GCC 3.2, DWARF 2, i686-pc-linux-gnu; no new regressions.  OK
> to commit?

First of all, think with me for a moment here.

As Daniel Berlin pointed out, the demangler is behaving correctly.  The
return type is part of the mangled signature in this case, and must be.
However, for GDB's purposes, is it _necessary_ or _useful_ to have said
mangled name?  If not, for another project I already have a
cplus_demangle wrapper which plays with the resulting names.  Adapting
it to detect and remove return types would probably be easy.

I am not strong in this area of C++, but as far as I know this should
suffice; the demangled name of such a function will always include the
template parameters; and the template-id must be unique in the program
(right?  Not sure if the ODR comes into play here or not) so either
there is only one possible return value or the template parameters
uniquely identify the return value.

i.e. you can't have a program with
  int foo<int> (int)
and
  long foo<int> (int)
in it!


That said, I still think your patch is OK; on the condition that it
handles the test case the comment you're removing refers to.  Something
like:
  int foo<operator() (B&)>
or whatever it was in the right syntax.  Does it, and can you add that
to the maint.exp tests?

> 
> David Carlton
> carlton at bactrian dot org
> 
> 2003-04-18  David Carlton  <carlton at bactrian dot org>
> 
> 	* cp-support.c (cp_find_first_component): Accept 'operator' in
> 	more locations.
> 
> 2003-04-18  David Carlton  <carlton at bactrian dot org>
> 
> 	* gdb.c++/maint.exp (test_first_component): Add tests for
> 	'operator' in more locations.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


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