Build fix: g++ 4.8 incorrectly disambiguates enum and member
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 26 Apr 2023 22:13:02 +0000 (18:13 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 28 Apr 2023 14:04:58 +0000 (10:04 -0400)
g++ 4.8 fails to build with the following error:

  commands/start.cpp: In function ‘cmd_error_code {anonymous}::start_tracing(const session_spec&)’:
  commands/start.cpp:123:76: error: ‘session_spec::type’ is not a class, namespace, or enumeration
    if (!listing_failed && sessions.size() == 0 && spec.type == session_spec::type::NAME) {
                                                                              ^
  commands/start.cpp:144:36: error: ‘session_spec::type’ is not a class, namespace, or enumeration
       if (spec.type != session_spec::type::NAME) {
                                    ^

The `type` member is renamed to type_ to workaround this compiler bug.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Id46ca4219d4d96db71a9d4523c3571303b2e97a7

src/bin/lttng/commands/destroy.cpp
src/bin/lttng/commands/start.cpp
src/bin/lttng/commands/stop.cpp
src/bin/lttng/utils.cpp
src/bin/lttng/utils.hpp

index b9fd53bbf620bbd7be275c5a0aabf6c24e3387f2..0bffb30bdb86ac1399516eba05c6bc74bb787e11 100644 (file)
@@ -272,7 +272,7 @@ cmd_error_code destroy_sessions(const session_spec& spec)
                }
        }();
 
-       if (!listing_failed && sessions.size() == 0 && spec.type == session_spec::type::NAME) {
+       if (!listing_failed && sessions.size() == 0 && spec.type_ == session_spec::type::NAME) {
                ERR_FMT("Session `{}` not found", spec.value);
                return CMD_ERROR;
        }
@@ -289,7 +289,7 @@ cmd_error_code destroy_sessions(const session_spec& spec)
                } catch (const lttng::ctl::error& ctl_exception) {
                        switch (ctl_exception.code()) {
                        case LTTNG_ERR_NO_SESSION:
-                               if (spec.type != session_spec::type::NAME) {
+                               if (spec.type_ != session_spec::type::NAME) {
                                        /* Session destroyed during command, ignore and carry-on. */
                                        sub_ret = CMD_SUCCESS;
                                        break;
@@ -335,10 +335,7 @@ int cmd_destroy(int argc, const char **argv)
        bool success;
        static poptContext pc;
        const char *leftover = nullptr;
-       struct session_spec spec = {
-               .type = session_spec::NAME,
-               .value = nullptr,
-       };
+       struct session_spec spec(session_spec::type::NAME);
        session_list const sessions;
 
        pc = poptGetContext(nullptr, argc, argv, long_options, 0);
@@ -358,10 +355,10 @@ int cmd_destroy(int argc, const char **argv)
                        list_cmd_options(stdout, long_options);
                        goto end;
                case OPT_ALL:
-                       spec.type = session_spec::ALL;
+                       spec.type_ = session_spec::type::ALL;
                        break;
                case OPT_ENABLE_GLOB:
-                       spec.type = session_spec::GLOB_PATTERN;
+                       spec.type_ = session_spec::type::GLOB_PATTERN;
                        break;
                default:
                        command_ret = CMD_UNDEFINED;
index 87df0f72f13273cacfa731784d4826e1d838d376..79c9d89734efad73d1f753e3567bde632c11276f 100644 (file)
@@ -120,7 +120,7 @@ cmd_error_code start_tracing(const session_spec& spec) noexcept
                }
        }();
 
-       if (!listing_failed && sessions.size() == 0 && spec.type == session_spec::type::NAME) {
+       if (!listing_failed && sessions.size() == 0 && spec.type_ == session_spec::type::NAME) {
                ERR_FMT("Session `{}` not found", spec.value);
                return CMD_ERROR;
        }
@@ -141,7 +141,7 @@ cmd_error_code start_tracing(const session_spec& spec) noexcept
                                sub_ret = CMD_SUCCESS;
                                break;
                        case LTTNG_ERR_NO_SESSION:
-                               if (spec.type != session_spec::type::NAME) {
+                               if (spec.type_ != session_spec::type::NAME) {
                                        /* Session destroyed during command, ignore and carry-on. */
                                        sub_ret = CMD_SUCCESS;
                                        break;
@@ -189,10 +189,7 @@ int cmd_start(int argc, const char **argv)
        bool success = true;
        static poptContext pc;
        const char *leftover = nullptr;
-       session_spec session_spec = {
-               .type = session_spec::NAME,
-               .value = nullptr,
-       };
+       session_spec session_spec(session_spec::type::NAME);
 
        pc = poptGetContext(nullptr, argc, argv, long_options, 0);
        poptReadDefaultConfig(pc, 0);
@@ -211,10 +208,10 @@ int cmd_start(int argc, const char **argv)
                        list_cmd_options(stdout, long_options);
                        goto end;
                case OPT_ENABLE_GLOB:
-                       session_spec.type = session_spec::GLOB_PATTERN;
+                       session_spec.type_ = session_spec::type::GLOB_PATTERN;
                        break;
                case OPT_ALL:
-                       session_spec.type = session_spec::ALL;
+                       session_spec.type_ = session_spec::type::ALL;
                        break;
                default:
                        command_ret = CMD_UNDEFINED;
index 3bed42f93348169ff956d92ef9eaef94fdab1761..cc4296bfb71f0e589182056ef2624477d263cf89 100644 (file)
@@ -149,7 +149,7 @@ cmd_error_code stop_tracing(const session_spec& spec) noexcept
                }
        }();
 
-       if (!listing_failed && sessions.size() == 0 && spec.type == session_spec::type::NAME) {
+       if (!listing_failed && sessions.size() == 0 && spec.type_ == session_spec::type::NAME) {
                ERR_FMT("Session `{}` not found", spec.value);
                return CMD_ERROR;
        }
@@ -170,7 +170,7 @@ cmd_error_code stop_tracing(const session_spec& spec) noexcept
                                sub_ret = CMD_SUCCESS;
                                break;
                        case LTTNG_ERR_NO_SESSION:
-                               if (spec.type != session_spec::type::NAME) {
+                               if (spec.type_ != session_spec::type::NAME) {
                                        /* Session destroyed during command, ignore and carry-on. */
                                        sub_ret = CMD_SUCCESS;
                                        break;
@@ -218,10 +218,7 @@ int cmd_stop(int argc, const char **argv)
        bool success = true;
        static poptContext pc;
        const char *leftover = nullptr;
-       struct session_spec session_spec = {
-               .type = session_spec::NAME,
-               .value = nullptr,
-       };
+       struct session_spec session_spec(session_spec::type::NAME);
 
        pc = poptGetContext(nullptr, argc, argv, long_options, 0);
        poptReadDefaultConfig(pc, 0);
@@ -240,10 +237,10 @@ int cmd_stop(int argc, const char **argv)
                        list_cmd_options(stdout, long_options);
                        goto end;
                case OPT_ENABLE_GLOB:
-                       session_spec.type = session_spec::GLOB_PATTERN;
+                       session_spec.type_ = session_spec::type::GLOB_PATTERN;
                        break;
                case OPT_ALL:
-                       session_spec.type = session_spec::ALL;
+                       session_spec.type_ = session_spec::type::ALL;
                        break;
                default:
                        command_ret = CMD_UNDEFINED;
index 5b0c461d98a2d8f58627e76e3c6695914f606194..cf9590c3eba081c5905af0c8293fbb47f75a80fd 100644 (file)
@@ -708,16 +708,15 @@ session_list get_sessions(const FilterFunctionType& filter, bool return_first_ma
 
 session_list list_sessions(const struct session_spec& spec)
 {
-       switch (spec.type) {
-       case session_spec::NAME:
+       switch (spec.type_) {
+       case session_spec::type::NAME:
                if (spec.value == nullptr) {
                        const auto configured_name =
                                lttng::make_unique_wrapper<char, lttng::free>(get_session_name());
 
                        if (configured_name) {
-                               const struct session_spec new_spec = {
-                                       .type = session_spec::NAME, .value = configured_name.get()
-                               };
+                               const struct session_spec new_spec(session_spec::type::NAME,
+                                                                  configured_name.get());
 
                                return list_sessions(new_spec);
                        }
@@ -730,11 +729,11 @@ session_list list_sessions(const struct session_spec& spec)
                                return strcmp(session.name, spec.value) == 0;
                        },
                        true);
-       case session_spec::GLOB_PATTERN:
+       case session_spec::type::GLOB_PATTERN:
                return get_sessions([&spec](const lttng_session& session) {
                        return fnmatch(spec.value, session.name, 0) == 0;
                });
-       case session_spec::ALL:
+       case session_spec::type::ALL:
                return get_sessions([](const lttng_session&) { return true; });
        }
 
index 990bad57517bf33031c059fe667be5075318e19d..262775d1d6bf0513e75f83c1ff0a939c68266b7d 100644 (file)
@@ -26,13 +26,19 @@ extern pid_t sessiond_pid;
 struct cmd_struct;
 
 struct session_spec {
-       enum type {
+       enum class type {
                NAME,
                GLOB_PATTERN,
                ALL,
        };
 
-       type type;
+       explicit session_spec(type spec_type, const char *name_or_pattern = nullptr) noexcept :
+               type_(spec_type), value(name_or_pattern)
+       {
+       }
+
+       /* Disambiguate type enum from the member for buggy g++ versions. */
+       type type_;
        const char *value;
 };
 
This page took 0.033326 seconds and 4 git commands to generate.