From 42a11b8f4c8d98b33fa1eadcdcda96253e651f0b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 26 Apr 2023 18:13:02 -0400 Subject: [PATCH] Build fix: g++ 4.8 incorrectly disambiguates enum and member MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Change-Id: Id46ca4219d4d96db71a9d4523c3571303b2e97a7 --- src/bin/lttng/commands/destroy.cpp | 13 +++++-------- src/bin/lttng/commands/start.cpp | 13 +++++-------- src/bin/lttng/commands/stop.cpp | 13 +++++-------- src/bin/lttng/utils.cpp | 13 ++++++------- src/bin/lttng/utils.hpp | 10 ++++++++-- 5 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/bin/lttng/commands/destroy.cpp b/src/bin/lttng/commands/destroy.cpp index b9fd53bbf..0bffb30bd 100644 --- a/src/bin/lttng/commands/destroy.cpp +++ b/src/bin/lttng/commands/destroy.cpp @@ -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; diff --git a/src/bin/lttng/commands/start.cpp b/src/bin/lttng/commands/start.cpp index 87df0f72f..79c9d8973 100644 --- a/src/bin/lttng/commands/start.cpp +++ b/src/bin/lttng/commands/start.cpp @@ -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; diff --git a/src/bin/lttng/commands/stop.cpp b/src/bin/lttng/commands/stop.cpp index 3bed42f93..cc4296bfb 100644 --- a/src/bin/lttng/commands/stop.cpp +++ b/src/bin/lttng/commands/stop.cpp @@ -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; diff --git a/src/bin/lttng/utils.cpp b/src/bin/lttng/utils.cpp index 5b0c461d9..cf9590c3e 100644 --- a/src/bin/lttng/utils.cpp +++ b/src/bin/lttng/utils.cpp @@ -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(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; }); } diff --git a/src/bin/lttng/utils.hpp b/src/bin/lttng/utils.hpp index 990bad575..262775d1d 100644 --- a/src/bin/lttng/utils.hpp +++ b/src/bin/lttng/utils.hpp @@ -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; }; -- 2.34.1