Build fix: specialization of template in different namespace
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Wed, 15 Jun 2022 19:09:03 +0000 (15:09 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 17 Jun 2022 14:56:35 +0000 (10:56 -0400)
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<class T, class Char, class Enable> struct fmt::v8::formatter' in different namespace [-fpermissive]
 struct fmt::formatter<std::type_info> : fmt::formatter<std::string> {
             ^
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<class T, class Char, class Enable> 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<class T, class Char, class Enable> struct fmt::v8::formatter' in different namespace [-fpermissive]
 struct fmt::formatter<lttng::sessiond::ust::registry_event> : fmt::formatter<std::string> {
             ^
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<class T, class Char, class Enable> 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<MappingIntegerType>::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<class T, class Char, class Enable> struct fmt::v8::formatter' in different namespace [-fpermissive]
 struct fmt::formatter<ust_app> : fmt::formatter<std::string> {
             ^
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<class T, class Char, class Enable> 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 <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I6b931065b37e6e9ba97f87c754c15808506c2ba8

src/bin/lttng-sessiond/field.cpp
src/bin/lttng-sessiond/ust-app.hpp
src/bin/lttng-sessiond/ust-registry-event.hpp
src/common/format.hpp

index df2808841e6c2dfb324a635c0aa85ec1e520fd64..604092a3b86c9c5352a3ab3cd649f6ad77cc2312 100644 (file)
@@ -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)}
index 34376a63df9ded3af5ca1ef0bd26b20a319cb639..0db462e7d7fe22d8eb8194c1418e2ca7ab8541e4 100644 (file)
@@ -326,19 +326,20 @@ struct ust_app {
        struct lttng_ht *token_to_event_notifier_rule_ht;
 };
 
+namespace fmt {
 template <>
-struct fmt::formatter<ust_app> : fmt::formatter<std::string> {
+struct formatter<ust_app> : formatter<std::string> {
        template <typename FormatCtx>
        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
 
index 340c6b455a5b515a70d51cc0ebd2b2ca977dc0f1..06f24a12050f4942316ba614f5eed2dd390d728d 100644 (file)
@@ -63,17 +63,19 @@ void registry_event_destroy(registry_event *event);
 } /* namespace sessiond */
 } /* namespace lttng */
 
+namespace fmt {
 template <>
-struct fmt::formatter<lttng::sessiond::ust::registry_event> : fmt::formatter<std::string> {
+struct formatter<lttng::sessiond::ust::registry_event> : formatter<std::string> {
        template <typename FormatCtx>
        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 */
index 73b363408f49cf499f326f601c1bdd0cd8835478..dace2c027b31a1d9926f63c0fb55f3f4e4f5ed95 100644 (file)
@@ -19,19 +19,21 @@ DIAGNOSTIC_IGNORE_DUPLICATED_BRANCHES
 #include <vendor/fmt/core.h>
 DIAGNOSTIC_POP
 
+namespace fmt {
 template <>
-struct fmt::formatter<std::type_info> : fmt::formatter<std::string> {
+struct formatter<std::type_info> : formatter<std::string> {
        template <typename FormatCtx>
        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<std::string>::format(demangled_name, ctx) :
-                                             fmt::formatter<std::string>::format(type_info.name(), ctx);
+               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.029289 seconds and 4 git commands to generate.