This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: C++ demangler horrors
"H. J. Lu" <hjl@lucon.org> writes:
> On Thu, Jun 26, 2003 at 10:25:24PM +0200, Oscar Fuentes wrote:
>> Phil Edwards <phil@jaj.com> writes:
>>
>> > I very much doubt if this is going to happen, for three reasons:
>> >
>> > 1) Nobody will write a C++ replacement for vector and string. That's just
>> > unnecessary reinvention of the wheel.
>>
>> Hi.
>>
>> Some time ago I was forced to write a vector & string replacement. It
>> is not highly optimized, nor it has support for allocators, but I'm
>> using it on a daily basis. The string is just a vector of chars plus
>> the guarantee of a '\0' at the end.
>>
>> If you are interested, send me the *files* (not the patches, I'm not a
>> gcc developer and I don't want to setup a build environment for it)
>> and I'll see if I can make it work.
>>
>
> Here is it is. Just untar and do
>
> # ./configure
> # make
Ok. The good news is that the demangler compiles with my vector/string
replacement (dynstring is out as well) and produces the same output as
the version you sent me.
The bad news is that I can't figure out why the demangler is producing
that output. Obviously I don't know how to use the demangler. My basic
test is below.
Please explain on how I must invoke the demangler to actually demangle
the name.
// File: main.cpp
// compiled with g++ -static main.cpp -L./lib/.libs -ldemangler -liberty -o test
// with gcc 3.3 on i386-unknown-netbsdelf1.6
#include <stdlib.h>
#include <stdio.h>
extern "C" char*
__cxa_demangle(char const* mangled_name, char* buf, size_t* n,
int* status);
#include <stdio.h>
int main() {
// this one yields "long"
const char *mn = "lexicographical_compare__H2ZPCScZPCSc_X01X01X11X11_b";
// this one yields "float"
// const char *mn = "finish__Q39__gnu_cxx9demangler28_GLOBAL_$N$demangle.ccSZm1gbPCcUiPcPUiPi";
// this one gives "Error -2" (Invalid mangled name)
// const char *mn = "_Q39__gnu_cxx9demangler28_GLOBAL_$N$demangle.ccSZm1gb$builtin_type_c";
int err;
char *dn = __cxa_demangle(mn, 0, 0, &err);
if( dn == 0 ) {
printf("Error %d\n", err);
}
else {
printf("%s\n", dn);
}
}