Clean-up: coverity warns of uncaught exception during logging
[lttng-tools.git] / src / bin / lttng-sessiond / field.cpp
index df51df488498589f9f4524f6025cce8a4f2366a4..c00f6d1351085ec92b5bf7dd75c8ea6f5cf33fdc 100644 (file)
@@ -66,6 +66,9 @@ bool lst::type::operator!=(const lst::type& other) const noexcept
 lst::field::field(std::string in_name, lst::type::cuptr in_type) :
        name{std::move(in_name)}, _type{std::move(in_type)}
 {
+       if (!_type) {
+               LTTNG_THROW_ERROR(fmt::format("Invalid type used to create field: field name = `{}`", name));
+       }
 }
 
 void lst::field::accept(lst::field_visitor& visitor) const
@@ -78,6 +81,20 @@ bool lst::field::operator==(const lst::field& other) const noexcept
        return name == other.name && *_type == *other._type;
 }
 
+lst::type::cuptr lst::field::move_type() noexcept
+{
+       return std::move(_type);
+}
+
+const lst::type &lst::field::get_type() const
+{
+       if (_type) {
+               return *_type;
+       } else {
+               LTTNG_THROW_ERROR(fmt::format("Invalid attempt to access field type after transfer: field name = `{}`", name));
+       }
+}
+
 lst::integer_type::integer_type(unsigned int in_alignment,
                enum lst::byte_order in_byte_order,
                unsigned int in_size,
@@ -174,17 +191,36 @@ lst::enumeration_type::enumeration_type(unsigned int in_alignment,
 {
 }
 
+/*
+ * Due to a bug in g++ < 7.1, these specializations must be enclosed in the namespaces
+ * rather than using the usual `namespace::namespace::function` notation:
+ * see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480.
+ */
 namespace lttng {
 namespace sessiond {
 namespace trace {
 template <>
-void lst::signed_enumeration_type::accept(type_visitor& visitor) const
+void signed_enumeration_type::accept(type_visitor& visitor) const
+{
+       visitor.visit(*this);
+}
+
+template <>
+void unsigned_enumeration_type::accept(type_visitor& visitor) const
+{
+       visitor.visit(*this);
+}
+
+template <>
+void variant_type<lst::signed_enumeration_type::mapping::range_t::range_integer_t>::accept(
+               lst::type_visitor& visitor) const
 {
        visitor.visit(*this);
 }
 
 template <>
-void lst::unsigned_enumeration_type::accept(type_visitor& visitor) const
+void variant_type<lst::unsigned_enumeration_type::mapping::range_t::range_integer_t>::accept(
+               lst::type_visitor& visitor) const
 {
        visitor.visit(*this);
 }
@@ -344,7 +380,7 @@ void lst::null_terminated_string_type::accept(type_visitor& visitor) const
 }
 
 lst::structure_type::structure_type(unsigned int in_alignment, fields in_fields) :
-       type(in_alignment), _fields{std::move(in_fields)}
+       type(in_alignment), fields_{std::move(in_fields)}
 {
 }
 
@@ -352,35 +388,10 @@ bool lst::structure_type::_is_equal(const type& base_other) const noexcept
 {
        const auto &other = static_cast<decltype(*this)&>(base_other);
 
-       return fields_are_equal(this->_fields, other._fields);
+       return fields_are_equal(this->fields_, other.fields_);
 }
 
 void lst::structure_type::accept(type_visitor& visitor) const
 {
        visitor.visit(*this);
 }
-
-lst::variant_type::variant_type(unsigned int in_alignment,
-               field_location in_selector_field_location,
-               choices in_choices) :
-       type(in_alignment),
-       selector_field_location{std::move(in_selector_field_location)},
-       _choices
-{std::move(in_choices)}
-{
-}
-
-bool lst::variant_type::_is_equal(const type& base_other) const noexcept
-{
-       const auto &other = static_cast<decltype(*this)&>(base_other);
-
-       return this->selector_field_location == other.selector_field_location &&
-                       fields_are_equal(this->_choices
-, other._choices
-);
-}
-
-void lst::variant_type::accept(type_visitor& visitor) const
-{
-       visitor.visit(*this);
-}
This page took 0.031403 seconds and 4 git commands to generate.