This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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: __cxa_demangle


>But if you pass "i" to __cxa_demangle(), then would should it return?
>I think it should return 'int'.  It can't know that there is an object
>called 'i' because it doesn't have the symbol table.

Currently it returns 'int.' 

ie, for the following:

#include <string>
#include <iostream>
#include <cxxabi.h>

const char*
demangle(const std::string& mangled)
{
  const char* name;
  int status = 0;
  name = abi::__cxa_demangle(mangled.c_str(), 0, 0, &status);
  if (!name)
    {
      switch (status)
	{
	case 0:
	  name = "error code = 0: success";
	  break;
	case -1:
	  name = "error code = -1: memory allocation failure";
	  break;
	case -2:
	  name = "error code = -2: invalid mangled name";
	  break;
	case -3:
	  name = "error code = -3: invalid arguments";
	  break;
	default:
	  name = "error code unknown - who knows what happened";
	}
    }
  return name;
}

int main()
{
  using namespace std;
  const string test1("i");
  const string test2("_Zi");
  const char* status;

  // "i"
  status = demangle(test1);
  cout << "test: " << test1 << " \t" << "demangled: " << status << endl;
  
  // "_Zi"
  status = demangle(test2);
  cout << "test: " << test2 << " \t" << "demangled: " << status << endl;

  return 0;
}

%a.out 
test: i         demangled: int
test: _Zi       demangled: error code = -2: invalid mangled name

Does this help?

-benjamin


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