Commit | Line | Data |
---|---|---|
05aa7e19 JG |
1 | /* |
2 | * Copyright (C) 2022 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
3 | * | |
4 | * SPDX-License-Identifier: LGPL-2.1-only | |
5 | * | |
6 | */ | |
7 | #ifndef LTTNG_FORMAT_H | |
8 | #define LTTNG_FORMAT_H | |
9 | ||
10 | #include <common/macros.hpp> | |
11 | ||
5bb4ff54 JG |
12 | #include <string> |
13 | #include <cxxabi.h> | |
14 | ||
05aa7e19 JG |
15 | DIAGNOSTIC_PUSH |
16 | DIAGNOSTIC_IGNORE_SUGGEST_ATTRIBUTE_FORMAT | |
17 | DIAGNOSTIC_IGNORE_DUPLICATED_BRANCHES | |
18 | #define FMT_HEADER_ONLY | |
19 | #include <vendor/fmt/core.h> | |
20 | DIAGNOSTIC_POP | |
21 | ||
11bcbf89 JG |
22 | /* |
23 | * Due to a bug in g++ < 7.1, this specialization must be enclosed in the fmt namespace, | |
24 | * see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480. | |
25 | */ | |
e2c2bec2 | 26 | namespace fmt { |
5bb4ff54 | 27 | template <> |
e2c2bec2 | 28 | struct formatter<std::type_info> : formatter<std::string> { |
5bb4ff54 JG |
29 | template <typename FormatCtx> |
30 | typename FormatCtx::iterator format(const std::type_info& type_info, FormatCtx& ctx) | |
31 | { | |
32 | int status; | |
33 | auto demangled_name = abi::__cxa_demangle(type_info.name(), nullptr, 0, &status); | |
e2c2bec2 JR |
34 | auto it = status == 0 ? formatter<std::string>::format(demangled_name, ctx) : |
35 | formatter<std::string>::format(type_info.name(), ctx); | |
5bb4ff54 JG |
36 | |
37 | free(demangled_name); | |
38 | return it; | |
39 | } | |
40 | }; | |
e2c2bec2 | 41 | } /* namespace fmt */ |
5bb4ff54 | 42 | |
05aa7e19 | 43 | #endif /* LTTNG_FORMAT_H */ |