This library implements C++ name demangling for GNU GCC. GNU conforms to the name mangling scheme of the Itanium C++ ABI.
The library is written in plain C with C99 extensions.
Demangle
is licensed under the Apache License version 2.
The current state of the library has had only minimal testing for demangling of <expression> blocks (e.g. within decltype
specifications). Ternary expressions and parameter lists inside such expressions are currently not handled. A few more (special) operators may be missing. As an aside: these parts also remain "unimplemented" (or partially implemented) because of the lack of good test cases. These parts are quite rare.
There is a single function:
int demangle(char *plain, size_t size, const char *mangled);
The first parameter, plain
, is the output (demangled string); the second parameter is the size of this buffer. The third parameter, mangled
, is the input string.
The function returns 0 (zero) on failure, and 1 on success.
- Only Itanium ABI (no support for Microsoft Visual C/C++). More specifically, it focusses on GCC and clang.
- Only C++ (no Java, Rust, ...).
- No support for an extra leading underscore; if you have a compiler that prefixes every symbol with an underscore, you ought to skip it before calling the
demangle
function. (A leading underscore on every symbol is common on COFF files, but not on ELF).
The canonical implementation for name demangling is cp-demangle
, originally from the libiberty
project. While I read the story of how the early releases of cp-demangle were riddled with bugs, those were the early versions. The current version is probably the most field-tested demangler for GNU C++.
The reason I decided to make my own, is the license: cp-demangle
is GPL. While I release my demangle library as open-source, I want to be able to use it in commercial projects as well.
As an aside, for testing, I used many of the tests in the file demangle-expected.txt
, which is part of the cp-demangle
project. However, I did not look at the source code for cp-demangle
. I therefore consider this code a clean-room implementation.
The official docmentation of the Itanium C++ ABI covers the name mangling syntax and semantics in chapter 5.
The Itanium ABI documentation has omissions and a few errors, however. Guillaume Chatelet collected additional notes on the format.