Fixed test name-demangler relying on faulty string information.

Fortune for opaque_handle's current commit: Future small blessing − 末小吉
master
Avril 3 years ago
parent 8dea5823a5
commit da8429e49c
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -34,22 +34,21 @@ static std::string demangle_name(const char* mangled)
int _status;
};
size_t len;
int status;
char * demangled = abi::__cxa_demangle(mangled, nullptr, &len, &status);
int status = 0;
char * demangled = abi::__cxa_demangle(mangled, nullptr, nullptr /* This never seems to be even close to accurate, it's always off by a long shot and idk why? */, &status);
const auto c_str_to_string = [len](char* str)
auto c_str_to_string = [](char* str)
noexcept(std::is_nothrow_constructible_v<std::string, const char*, size_t>)
{
const auto _free = [&]() { free(static_cast<void*>(str)); };
if constexpr(std::is_nothrow_constructible_v<std::string, const char*, size_t>) {
std::string v{str, len};
std::string v{str};
_free();
return v;
} else {
try {
std::string v{str, len};
std::string v{str};
_free();
return v;
} catch(...) {
@ -67,7 +66,8 @@ static std::string demangle_name(const char* mangled)
inline static std::string demangle_name(const std::string& mangled)
{
return demangle_name(mangled.c_str());
const auto& tmp = mangled;
return demangle_name(tmp.c_str());
}
static inline void s_puts(const auto& string, FILE* to = nullptr)
@ -87,12 +87,14 @@ static void print_name(const std::type_info& type)
const char* name = type.name();
s_puts("type holds: ");
try {
s_puts(demangle_name(name));
s_puts("\n");
} catch(demangle_failed& err) {
s_puts("<mangled> ");
const auto dm = demangle_name(name);
s_puts("`");
s_puts(dm);
s_puts("`\n");
} catch(const demangle_failed& err) {
s_puts("<mangled> `");
s_puts(name);
s_puts("\n");
s_puts("`\n");
s_puts("Failed to demangle name: ", stderr);
s_puts(err.what(), stderr);

Loading…
Cancel
Save