diff --git a/include/common/mir/events/event_type_to_string.h b/include/common/mir/events/event_type_to_string.h index 3ab38f14ff0..2f0bef097bf 100644 --- a/include/common/mir/events/event_type_to_string.h +++ b/include/common/mir/events/event_type_to_string.h @@ -23,6 +23,7 @@ namespace mir { std::string event_type_to_string(MirEventType t); +char const* event_type_to_c_str(MirEventType t); } #endif // MIR_EVENT_TYPE_TO_STRING_H_ diff --git a/include/common/mir_toolkit/events/event.h b/include/common/mir_toolkit/events/event.h index 7af0fd17844..78ddbb0be1a 100644 --- a/include/common/mir_toolkit/events/event.h +++ b/include/common/mir_toolkit/events/event.h @@ -173,6 +173,7 @@ MirWindowPlacementEvent const* mir_event_get_window_placement_event(MirEvent con * \param[in] event The event to reference * \return The event pointer to now use */ +[[deprecated("Not meaningful: legacy of mirclient API")]] MirEvent const* mir_event_ref(MirEvent const* event) __attribute__((warn_unused_result)); /** @@ -180,6 +181,7 @@ MirEvent const* mir_event_ref(MirEvent const* event) __attribute__((warn_unused_ * * \param[in] event The event to un-reference */ +[[deprecated("Not meaningful: legacy of mirclient API")]] void mir_event_unref(MirEvent const* event); #ifdef __cplusplus diff --git a/src/common/event.cpp b/src/common/event.cpp index 45e5d660817..3e01dd5ee7f 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -19,7 +19,7 @@ #include "handle_event_exception.h" #include "mir/events/event_type_to_string.h" -#include "mir/log.h" +#include #include "mir_toolkit/events/event.h" #include "mir/events/event_private.h" @@ -30,7 +30,6 @@ #include "mir_toolkit/events/orientation_event.h" #include "mir_toolkit/events/input_device_state_event.h" -#include #include namespace ml = mir::logging; @@ -43,9 +42,8 @@ void expect_event_type(EventType const* ev, MirEventType t) MIR_HANDLE_EVENT_EXC auto type = ev->type(); if (type != t) { - mir::log_critical("Expected " + mir::event_type_to_string(t) + " but event is of type " + - mir::event_type_to_string(type)); - abort(); + mir::fatal_error("Expected %s but event is of type %s", + mir::event_type_to_c_str(t), mir::event_type_to_c_str(type)); } }) @@ -53,13 +51,19 @@ void expect_index_in_range(size_t size, size_t index) { if (index >= size) { - mir::log_critical("Index out of range in event data access"); - abort(); + mir::fatal_error("Index out of range in event data access"); } } } -std::string mir::event_type_to_string(MirEventType t) +// GCC and Clang both ensure the switch is exhaustive. +// GCC, however, gets a "control reaches end of non-void function" warning without this +#ifndef __clang__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wreturn-type" +#endif + +char const* mir::event_type_to_c_str(MirEventType t) { switch (t) { @@ -79,11 +83,30 @@ std::string mir::event_type_to_string(MirEventType t) return "mir_event_type_input_device_state"; case mir_event_type_window_output: return "mir_event_type_window_output"; - default: - abort(); + case mir_event_type_window_placement: + return "mir_event_type_window_placement"; + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + case mir_event_type_key: + return "mir_event_type_key"; + case mir_event_type_motion: + return "mir_event_type_motion"; + case mir_event_type_input_configuration: + return "mir_event_type_input_configuration"; +#pragma GCC diagnostic pop } } +#ifndef __clang__ +#pragma GCC diagnostic pop +#endif + +std::string mir::event_type_to_string(MirEventType t) +{ + return event_type_to_c_str(t); +} + MirEventType mir_event_get_type(MirEvent const* ev) MIR_HANDLE_EVENT_EXCEPTION( { @@ -95,9 +118,7 @@ MirInputEvent const* mir_event_get_input_event(MirEvent const* ev) MIR_HANDLE_EV auto const type = ev->type(); if (type != mir_event_type_input) { - mir::log_critical("Expected input event but event is of type " + - mir::event_type_to_string(type)); - abort(); + mir::fatal_error("Expected input event but event is of type %s", mir::event_type_to_c_str(type)); } return ev->to_input(); diff --git a/src/common/events/window_placement_event.cpp b/src/common/events/window_placement_event.cpp index ca55675d7cc..936d1383e34 100644 --- a/src/common/events/window_placement_event.cpp +++ b/src/common/events/window_placement_event.cpp @@ -16,7 +16,9 @@ #include "mir/events/window_placement_event.h" -MirWindowPlacementEvent::MirWindowPlacementEvent() : MirEvent(mir_event_type_window_placement) +MirWindowPlacementEvent::MirWindowPlacementEvent() : + MirEvent(mir_event_type_window_placement), + placement_{0, 0, 0U, 0U} { } diff --git a/src/common/input/input_event.cpp b/src/common/input/input_event.cpp index 7edfae2a620..0ff6e6704b2 100644 --- a/src/common/input/input_event.cpp +++ b/src/common/input/input_event.cpp @@ -19,12 +19,13 @@ #include "mir/events/event_type_to_string.h" #include "mir/events/event_private.h" +#include "mir/fatal.h" #include "mir/log.h" +#include #include "../handle_event_exception.h" #include -#include namespace ml = mir::logging; @@ -33,31 +34,43 @@ namespace geom = mir::geometry; namespace { -std::string input_event_type_to_string(MirInputEventType input_event_type) +// GCC and Clang both ensure the switch is exhaustive. +// GCC, however, gets a "control reaches end of non-void function" warning without this +#ifndef __clang__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wreturn-type" +#endif + +char const* input_event_type_to_c_str(MirInputEventType input_event_type) { switch (input_event_type) { - case mir_input_event_type_key: - return "mir_input_event_type_key"; - case mir_input_event_type_touch: - return "mir_input_event_type_touch"; - case mir_input_event_type_pointer: - return "mir_input_event_type_pointer"; - default: - abort(); + case mir_input_event_type_key: + return "mir_input_event_type_key"; + case mir_input_event_type_touch: + return "mir_input_event_type_touch"; + case mir_input_event_type_pointer: + return "mir_input_event_type_pointer"; + case mir_input_event_type_keyboard_resync: + return "mir_input_event_type_keyboard_resync"; + case mir_input_event_types: + mir::fatal_error_abort("Sentinel value 'mir_input_event_types' not supported"); } } +#ifndef __clang__ +#pragma GCC diagnostic pop +#endif + template -void expect_event_type(EventType const* ev, MirEventType t) MIR_HANDLE_EVENT_EXCEPTION( +void expect_event_type(EventType const* ev, MirEventType expect) { - if (ev->type() != t) + if (auto const actual = ev->type(); actual != expect) { - mir::log_critical("Expected " + mir::event_type_to_string(t) + " but event is of type " + - mir::event_type_to_string(ev->type())); - abort(); + mir::fatal_error_abort("Expected %s but event is of type %s", + mir::event_type_to_c_str(expect), mir::event_type_to_c_str(actual)); } -}) +} } MirInputEventType mir_input_event_get_type(MirInputEvent const* ev) MIR_HANDLE_EVENT_EXCEPTION( @@ -111,9 +124,8 @@ MirKeyboardEvent const* mir_input_event_get_keyboard_event(MirInputEvent const* { if (ev->input_type() != mir_input_event_type_key) { - mir::log_critical("expected key input event but event was of type " + - input_event_type_to_string(ev->input_type())); - abort(); + mir::fatal_error_abort("expected key input event but event was of type %s", + input_event_type_to_c_str(ev->input_type())); } return reinterpret_cast(ev); @@ -155,9 +167,8 @@ MirTouchEvent const* mir_input_event_get_touch_event(MirInputEvent const* ev) MI { if(ev->input_type() != mir_input_event_type_touch) { - mir::log_critical("expected touch input event but event was of type " + - input_event_type_to_string(ev->input_type())); - abort(); + mir::fatal_error_abort("expected touch input event but event was of type %s", + input_event_type_to_c_str(ev->input_type())); } return reinterpret_cast(ev); @@ -172,8 +183,7 @@ MirTouchId mir_touch_event_id(MirTouchEvent const* event, size_t touch_index) MI { if (touch_index >= event->pointer_count()) { - mir::log_critical("touch index is greater than pointer count"); - abort(); + mir::fatal_error_abort("touch index is greater than pointer count"); } return event->id(touch_index); @@ -183,8 +193,7 @@ MirTouchAction mir_touch_event_action(MirTouchEvent const* event, size_t touch_i { if(touch_index > event->pointer_count()) { - mir::log_critical("touch index is greater than pointer count"); - abort(); + mir::fatal_error_abort("touch index is greater than pointer count"); } return static_cast(event->action(touch_index)); @@ -195,8 +204,7 @@ MirTouchTooltype mir_touch_event_tooltype(MirTouchEvent const* event, { if(touch_index > event->pointer_count()) { - mir::log_critical("touch index is greater than pointer count"); - abort(); + mir::fatal_error_abort("touch index is greater than pointer count"); } return event->tool_type(touch_index); @@ -207,8 +215,7 @@ float mir_touch_event_axis_value(MirTouchEvent const* event, { if(touch_index > event->pointer_count()) { - mir::log_critical("touch index is greater than pointer count"); - abort(); + mir::fatal_error_abort("touch index is greater than pointer count"); } switch (axis) @@ -238,9 +245,8 @@ MirPointerEvent const* mir_input_event_get_pointer_event(MirInputEvent const* ev { if(ev->input_type() != mir_input_event_type_pointer) { - mir::log_critical("expected pointer input event but event was of type " + - input_event_type_to_string(ev->input_type())); - abort(); + mir::fatal_error_abort("expected pointer input event but event was of type ", + input_event_type_to_c_str(ev->input_type())); } return reinterpret_cast(ev); @@ -303,8 +309,7 @@ float mir_pointer_event_axis_value(MirPointerEvent const* pev, MirPointerAxis ax case mir_pointer_axis_hscroll_value120: return pev->h_scroll().value120.as_value(); default: - mir::log_critical("Invalid axis enumeration " + std::to_string(axis)); - abort(); + mir::fatal_error_abort("Invalid axis enumeration %d", axis); } }) @@ -326,7 +331,6 @@ bool mir_pointer_event_axis_stop(MirPointerEvent const* pev, MirPointerAxis axis case mir_pointer_axis_hscroll_value120: return false; default: - mir::log_critical("Invalid axis enumeration " + std::to_string(axis)); - abort(); + mir::fatal_error_abort("Invalid axis enumeration %d", axis); } }) \ No newline at end of file diff --git a/src/common/symbols.map b/src/common/symbols.map index a6e8eef7507..3f73ccc844e 100644 --- a/src/common/symbols.map +++ b/src/common/symbols.map @@ -693,5 +693,6 @@ global: MIR_COMMON_2.18 { global: extern "C++" { MirTouchpadConfig::disable_with_external_mouse*; + mir::event_type_to_c_str*; }; } MIR_COMMON_2.17; \ No newline at end of file diff --git a/src/core/depth_layer.cpp b/src/core/depth_layer.cpp index 36b2cc84716..bf2fbfb61fc 100644 --- a/src/core/depth_layer.cpp +++ b/src/core/depth_layer.cpp @@ -16,24 +16,27 @@ #include "mir/depth_layer.h" +// GCC and Clang both ensure the switch is exhaustive. +// GCC, however, gets a "control reaches end of non-void function" warning without this #ifndef __clang__ -#include "mir/fatal.h" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wreturn-type" #endif -auto mir::mir_depth_layer_get_index(MirDepthLayer depth_layer) -> unsigned int +auto mir::mir_depth_layer_get_index(MirDepthLayer const depth_layer) -> unsigned int { switch (depth_layer) { - case mir_depth_layer_background: return 0; - case mir_depth_layer_below: return 1; - case mir_depth_layer_application: return 2; - case mir_depth_layer_always_on_top: return 3; - case mir_depth_layer_above: return 4; - case mir_depth_layer_overlay: return 5; + case mir_depth_layer_background: + case mir_depth_layer_below: + case mir_depth_layer_application: + case mir_depth_layer_always_on_top: + case mir_depth_layer_above: + case mir_depth_layer_overlay: + return depth_layer; } - // GCC and Clang both ensure the switch is exhaustive. - // GCC, however, gets a "control reaches end of non-void function" warning without this +} + #ifndef __clang__ - fatal_error_abort("Invalid MirDepthLayer in mir::mir_depth_layer_get_index()"); +#pragma GCC diagnostic pop #endif -} diff --git a/src/core/geometry/rectangles.cpp b/src/core/geometry/rectangles.cpp index f04218b79c5..57c1f36c53d 100644 --- a/src/core/geometry/rectangles.cpp +++ b/src/core/geometry/rectangles.cpp @@ -17,6 +17,7 @@ #include "mir/geometry/rectangles.h" #include "mir/geometry/displacement.h" #include +#include #include #include diff --git a/src/miral/window_specification_internal.cpp b/src/miral/window_specification_internal.cpp index af7af916d53..91dd2f6eac4 100644 --- a/src/miral/window_specification_internal.cpp +++ b/src/miral/window_specification_internal.cpp @@ -18,12 +18,6 @@ namespace { -template -void copy_if_set(Dest& dest, mir::optional_value const& source) -{ - if (source.is_set()) dest = source.value(); -} - template void copy_if_set(Dest& dest, std::weak_ptr const& source) { @@ -68,9 +62,9 @@ void copy_if_set( } -auto miral::make_surface_spec(WindowSpecification const& window_spec) -> mir::shell::SurfaceSpecification +auto miral::make_surface_spec(WindowSpecification const& miral_spec) -> mir::shell::SurfaceSpecification { - auto& spec = *window_spec.self; + auto& spec = *miral_spec.self; mir::shell::SurfaceSpecification result; copy_if_set(result.top_left, spec.top_left); copy_if_set(result.pixel_format, spec.pixel_format); diff --git a/src/server/graphics/platform_probe.cpp b/src/server/graphics/platform_probe.cpp index 38dcf853cad..55eeface8f6 100644 --- a/src/server/graphics/platform_probe.cpp +++ b/src/server/graphics/platform_probe.cpp @@ -23,10 +23,6 @@ #include "mir/shared_library_prober_report.h" #include "mir/udev/wrapper.h" -#ifndef __clang__ -#include "mir/fatal.h" -#endif - #include "platform_probe.h" #include @@ -140,6 +136,14 @@ bool is_same_device( } + +// GCC and Clang both ensure the switch is exhaustive. +// GCC, however, gets a "control reaches end of non-void function" warning without this +#ifndef __clang__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wreturn-type" +#endif + auto mg::modules_for_device( std::function(mir::SharedLibrary const&)> const& probe, std::vector> const& modules, @@ -240,23 +244,6 @@ auto mg::modules_for_device( switch(nested_selection) { -#ifndef __clang__ - /* We handle both enum variants below. - * GCC does not use this particular UB to provide a better diagnostic, - * so we need to provide a default case. - * - * As normal, leave it guarded by !Clang, so our clang builds will - * error out at compile-time if we add a new enum variant. - */ - default: - mir::fatal_error("Impossible TypePreference"); - // We can't get here, either, but sadly we can't mark mir::fatal_error as [[noreturn]] - // to get the compiler to enforce that 🤦‍♀️ - std::terminate(); - /* We need the default case to be *above* the following cases, or GCC will warn - * that we're jumping over the initialiser of nested_vec below - */ -#endif case TypePreference::prefer_nested: if (best_nested && best_nested->first.support_level >= mg::probe::supported) { @@ -276,6 +263,10 @@ auto mg::modules_for_device( } } +#ifndef __clang__ +#pragma GCC diagnostic push +#endif + auto mir::graphics::display_modules_for_device( std::vector> const& modules, options::ProgramOption const& options, diff --git a/src/server/report/reports.cpp b/src/server/report/reports.cpp index 9265c0b1c2b..922d512d8ef 100644 --- a/src/server/report/reports.cpp +++ b/src/server/report/reports.cpp @@ -42,6 +42,13 @@ enum class ReportOutput LTTNG }; +// GCC and Clang both ensure the switch is exhaustive. +// GCC, however, gets a "control reaches end of non-void function" warning without this +#ifndef __clang__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wreturn-type" +#endif + std::unique_ptr factory_for_type( mir::DefaultServerConfiguration& config, ReportOutput type) @@ -55,18 +62,11 @@ std::unique_ptr factory_for_type( case ReportOutput::LTTNG: return std::make_unique(); } -#ifndef __clang__ - /* - * Clang understands that the above switch is exhaustive, so only throw here to satisfy g++'s - * control-reaches-end-of-non-void-function diagnostic. - * - * This way if the above switch *becomes* non-exhaustive clang will fail to build for us. - */ +} - using namespace std::string_literals; - throw std::logic_error{"Requested unknown ReportOutput type:"s + std::to_string(static_cast(type))}; +#ifndef __clang__ +#pragma GCC diagnostic push #endif -} ReportOutput parse_report_option(std::string const& opt) {