From e2c2bec23d72b09ef5778dff54fa6ca4a34587bf Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Wed, 15 Jun 2022 15:09:03 -0400 Subject: [PATCH] Build fix: specialization of template in different namespace MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Observed issue ============== On older g++, such as gcc (Ubuntu 5.3.1-14ubuntu2) 5.3.1 20160413: make[3]: Entering directory '/tmp/virtenv/src/lttng-tools/src/bin/lttng-sessiond' CXX utils.lo In file included from ust-app.hpp:15:0, from lttng-sessiond.hpp:22, from utils.cpp:17: ../../../src/common/format.hpp:17:24: warning: unknown option after '#pragma GCC diagnostic' kind [-Wpragmas] DIAGNOSTIC_IGNORE_DUPLICATED_BRANCHES ^ In file included from ust-app.hpp:15:0, from lttng-sessiond.hpp:22, from utils.cpp:17: ../../../src/common/format.hpp:23:13: error: specialization of 'template struct fmt::v8::formatter' in different namespace [-fpermissive] struct fmt::formatter : fmt::formatter { ^ In file included from ../../../src/common/format.hpp:19:0, from ust-app.hpp:15, from lttng-sessiond.hpp:22, from utils.cpp:17: ../../../src/vendor/fmt/core.h:707:8: error: from definition of 'template struct fmt::v8::formatter' [-fpermissive] struct formatter { ^ In file included from ust-registry.hpp:20:0, from ust-app.hpp:19, from lttng-sessiond.hpp:22, from utils.cpp:17: ust-registry-event.hpp:66:13: error: specialization of 'template struct fmt::v8::formatter' in different namespace [-fpermissive] struct fmt::formatter : fmt::formatter { ^ In file included from ../../../src/common/format.hpp:19:0, from ust-app.hpp:15, from lttng-sessiond.hpp:22, from utils.cpp:17: ../../../src/vendor/fmt/core.h:707:8: error: from definition of 'template struct fmt::v8::formatter' [-fpermissive] struct formatter { ^ In file included from ust-app.hpp:19:0, from lttng-sessiond.hpp:22, from utils.cpp:17: ust-registry.hpp: In constructor 'lttng::sessiond::ust::registry_typed_enum::registry_typed_enum(const char*, const lttng_ust_ctl_enum_entry*, size_t)': ust-registry.hpp:111:45: error: 'lttng::sessiond::trace::integer_type::signedness' is not a class, namespace, or enumeration lttng::sessiond::trace::integer_type::signedness::SIGNED : ^ ust-registry.hpp:112:51: error: 'lttng::sessiond::trace::integer_type::signedness' is not a class, namespace, or enumeration lttng::sessiond::trace::integer_type::signedness::UNSIGNED), ^ In file included from lttng-sessiond.hpp:22:0, from utils.cpp:17: ust-app.hpp: At global scope: ust-app.hpp:330:13: error: specialization of 'template struct fmt::v8::formatter' in different namespace [-fpermissive] struct fmt::formatter : fmt::formatter { ^ In file included from ../../../src/common/format.hpp:19:0, from ust-app.hpp:15, from lttng-sessiond.hpp:22, from utils.cpp:17: ../../../src/vendor/fmt/core.h:707:8: error: from definition of 'template struct fmt::v8::formatter' [-fpermissive] struct formatter { ^ cc1plus: warning: unrecognized command line option '-Wno-gnu-folding-constant' cc1plus: warning: unrecognized command line option '-Wno-incomplete-setjmp-declaration' Makefile:855: recipe for target 'utils.lo' failed make[3]: *** [utils.lo] Error 1 This also applies to the following specializations: void lst::signed_enumeration_type::accept(type_visitor& visitor) const void lst::unsigned_enumeration_type::accept(type_visitor& visitor) const Problem ======= This is due to a now-fixed gcc bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42018 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 Solution ======== Put the template specializations inside the proper namespace. Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau Change-Id: I6b931065b37e6e9ba97f87c754c15808506c2ba8 --- src/bin/lttng-sessiond/field.cpp | 6 ++++++ src/bin/lttng-sessiond/ust-app.hpp | 7 ++++--- src/bin/lttng-sessiond/ust-registry-event.hpp | 6 ++++-- src/common/format.hpp | 8 +++++--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/bin/lttng-sessiond/field.cpp b/src/bin/lttng-sessiond/field.cpp index df2808841..604092a3b 100644 --- a/src/bin/lttng-sessiond/field.cpp +++ b/src/bin/lttng-sessiond/field.cpp @@ -153,6 +153,9 @@ lst::enumeration_type::enumeration_type(unsigned int in_alignment, { } +namespace lttng { +namespace sessiond { +namespace trace { template <> void lst::signed_enumeration_type::accept(type_visitor& visitor) const { @@ -164,6 +167,9 @@ void lst::unsigned_enumeration_type::accept(type_visitor& visitor) const { visitor.visit(*this); } +} /* namespace trace */ +} /* namespace sessiond */ +} /* namespace lttng */ lst::array_type::array_type(unsigned int in_alignment, type::cuptr in_element_type) : type(in_alignment), element_type{std::move(in_element_type)} diff --git a/src/bin/lttng-sessiond/ust-app.hpp b/src/bin/lttng-sessiond/ust-app.hpp index 34376a63d..0db462e7d 100644 --- a/src/bin/lttng-sessiond/ust-app.hpp +++ b/src/bin/lttng-sessiond/ust-app.hpp @@ -326,19 +326,20 @@ struct ust_app { struct lttng_ht *token_to_event_notifier_rule_ht; }; +namespace fmt { template <> -struct fmt::formatter : fmt::formatter { +struct formatter : formatter { template typename FormatCtx::iterator format(const ust_app& app, FormatCtx& ctx) { - return fmt::format_to(ctx.out(), + return format_to(ctx.out(), "{{ procname = `{}`, ppid = {}, pid = {}, uid = {}, gid = {}, version = {}.{}, registration time = {} }}", app.name, app.ppid, app.pid, app.uid, app.gid, app.v_major, app.v_minor, lttng::utils::time_to_iso8601_str(app.registration_time)); } }; - +} /* namespace fmt */ #ifdef HAVE_LIBLTTNG_UST_CTL diff --git a/src/bin/lttng-sessiond/ust-registry-event.hpp b/src/bin/lttng-sessiond/ust-registry-event.hpp index 340c6b455..06f24a120 100644 --- a/src/bin/lttng-sessiond/ust-registry-event.hpp +++ b/src/bin/lttng-sessiond/ust-registry-event.hpp @@ -63,17 +63,19 @@ void registry_event_destroy(registry_event *event); } /* namespace sessiond */ } /* namespace lttng */ +namespace fmt { template <> -struct fmt::formatter : fmt::formatter { +struct formatter : formatter { template typename FormatCtx::iterator format( const lttng::sessiond::ust::registry_event& event, FormatCtx& ctx) { - return fmt::format_to(ctx.out(), + return format_to(ctx.out(), "{{ name = `{}`, signature = `{}`, id = {}, session objd = {}, channel objd = {} }}", event.name, event.signature, event.id, event.session_objd, event.channel_objd); } }; +} /* namespace fmt */ #endif /* LTTNG_UST_REGISTRY_EVENT_H */ diff --git a/src/common/format.hpp b/src/common/format.hpp index 73b363408..dace2c027 100644 --- a/src/common/format.hpp +++ b/src/common/format.hpp @@ -19,19 +19,21 @@ DIAGNOSTIC_IGNORE_DUPLICATED_BRANCHES #include DIAGNOSTIC_POP +namespace fmt { template <> -struct fmt::formatter : fmt::formatter { +struct formatter : formatter { template typename FormatCtx::iterator format(const std::type_info& type_info, FormatCtx& ctx) { int status; auto demangled_name = abi::__cxa_demangle(type_info.name(), nullptr, 0, &status); - auto it = status == 0 ? fmt::formatter::format(demangled_name, ctx) : - fmt::formatter::format(type_info.name(), ctx); + auto it = status == 0 ? formatter::format(demangled_name, ctx) : + formatter::format(type_info.name(), ctx); free(demangled_name); return it; } }; +} /* namespace fmt */ #endif /* LTTNG_FORMAT_H */ -- 2.34.1