Clean-up: ensure all template parameter names end with Type
[lttng-tools.git] / src / common / format.hpp
index b49a793b9a83808e4ea2203dffe54e0b45f74982..67509c275bad365ee23c2bd86ec7ab6fe44df5aa 100644 (file)
@@ -9,6 +9,9 @@
 
 #include <common/macros.hpp>
 
+#include <string>
+#include <cxxabi.h>
+
 DIAGNOSTIC_PUSH
 DIAGNOSTIC_IGNORE_SUGGEST_ATTRIBUTE_FORMAT
 DIAGNOSTIC_IGNORE_DUPLICATED_BRANCHES
@@ -16,4 +19,27 @@ DIAGNOSTIC_IGNORE_DUPLICATED_BRANCHES
 #include <vendor/fmt/core.h>
 DIAGNOSTIC_POP
 
+/*
+ * Due to a bug in g++ < 7.1, this specialization must be enclosed in the fmt namespace,
+ * see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480.
+ */
+namespace fmt {
+template <>
+struct formatter<std::type_info> : formatter<std::string> {
+       template <typename FormatContextType>
+       typename FormatContextType::iterator format(const std::type_info& type_info,
+                                                   FormatContextType& ctx)
+       {
+               int status;
+               auto demangled_name =
+                       abi::__cxa_demangle(type_info.name(), nullptr, nullptr, &status);
+               auto it = status == 0 ? formatter<std::string>::format(demangled_name, ctx) :
+                                       formatter<std::string>::format(type_info.name(), ctx);
+
+               free(demangled_name);
+               return it;
+       }
+};
+} /* namespace fmt */
+
 #endif /* LTTNG_FORMAT_H */
This page took 0.023235 seconds and 4 git commands to generate.