Skip to content

Commit aafaa20

Browse files
committed
utils:
- replace utils::unreachable by macro, that also prints the current line and function, this is not possible with a constexpr function, so a macros has to be used
1 parent 716f8d5 commit aafaa20

File tree

26 files changed

+53
-51
lines changed

26 files changed

+53
-51
lines changed

src/discord/core.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
case ArtAsset::logo:
1616
return "logo";
1717
default:
18-
utils::unreachable();
18+
UNREACHABLE();
1919
}
2020
}
2121

src/game/graphic_helpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace {
2121
case MinoTransparency::Solid:
2222
return utils::to_underlying(transparency);
2323
default:
24-
utils::unreachable();
24+
UNREACHABLE();
2525
}
2626
}
2727
} // namespace

src/game/tetrion.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ u8 Tetrion::rotation_to_index(const Rotation from, const Rotation rotation_to) {
561561
if (from == Rotation::North and rotation_to == Rotation::West) {
562562
return 7;
563563
}
564-
utils::unreachable();
564+
UNREACHABLE();
565565
}
566566

567567
bool Tetrion::is_tetromino_position_valid(const Tetromino& tetromino) const {
@@ -628,7 +628,7 @@ bool Tetrion::move(const Tetrion::MoveDirection move_direction) {
628628
return true;
629629
}
630630

631-
utils::unreachable();
631+
UNREACHABLE();
632632
}
633633

634634
helper::optional<const Tetrion::WallKickTable*> Tetrion::get_wall_kick_table() const {
@@ -646,6 +646,6 @@ helper::optional<const Tetrion::WallKickTable*> Tetrion::get_wall_kick_table() c
646646
case helper::TetrominoType::O:
647647
return {};
648648
default:
649-
utils::unreachable();
649+
UNREACHABLE();
650650
}
651651
}

src/graphics/texture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Texture Texture::prerender_text(
3737
font.get(), text.c_str(), text_color, utils::sdl_color_from_color(background_color)
3838
);
3939
} else {
40-
utils::unreachable();
40+
UNREACHABLE();
4141
}
4242
if (surface == nullptr) {
4343
throw std::runtime_error(fmt::format("Failed to pre-render text into surface with error: {}", SDL_GetError()));

src/helper/color.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ namespace {
153153
return color.to_string(force_alpha);
154154
}
155155
default:
156-
utils::unreachable();
156+
UNREACHABLE();
157157
}
158158
}
159159

src/helper/color.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ struct Color {
208208
d_b = x_offset;
209209
break;
210210
default:
211-
utils::unreachable();
211+
UNREACHABLE();
212212
}
213213

214214

src/helper/utils.hpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,10 @@ namespace utils {
6161

6262
#if __cpp_lib_unreachable >= 202202L
6363
[[noreturn]] inline void unreachable() {
64-
#if !defined(NDEBUG)
65-
std::cerr << "UNREACHABLE\n";
66-
#endif
67-
6864
std::unreachable();
6965
}
7066
#else
7167
[[noreturn]] inline void unreachable() {
72-
#if !defined(NDEBUG)
73-
std::cerr << "UNREACHABLE\n";
74-
#endif
75-
7668
#if defined(_MSC_VER) && !defined(__clang__) // MSVC
7769
__assume(false);
7870
#else // GCC, Clang
@@ -125,9 +117,20 @@ namespace utils {
125117

126118
} // namespace utils
127119

128-
129120
#define UNUSED(x) (void(x)) // NOLINT(cppcoreguidelines-macro-usage)
130121

122+
#if !defined(NDEBUG)
123+
#define UNREACHABLE() /* NOLINT(cppcoreguidelines-macro-usage)*/ \
124+
do { \
125+
std::cerr << "UNREACHABLE " << (__FILE__) << ":" << (__LINE__) << " - " << (__FUNCTION__) << "\n"; \
126+
utils::unreachable(); \
127+
} while (false)
128+
#else
129+
#define UNREACHABLE() utils::unreachable // NOLINT(cppcoreguidelines-macro-usage)
130+
#endif
131+
// NOLINT(cppcoreguidelines-macro-usage)
132+
133+
131134
#if defined(NDEBUG)
132135
#define ASSERT(x) (UNUSED(x)) // NOLINT(cppcoreguidelines-macro-usage)
133136
#else

src/input/controller_input.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ input::ControllerInput::get_by_device_index(int device_index) {
126126
case NavigationEvent::TAB:
127127
throw std::runtime_error("Tab is not supported");
128128
default:
129-
utils::unreachable();
129+
UNREACHABLE();
130130
}
131131
}
132132

@@ -234,7 +234,7 @@ input::ControllerGameInput::ControllerGameInput(
234234
case input::MenuEvent::OpenSettings:
235235
return m_settings.open_settings.to_string();
236236
default:
237-
utils::unreachable();
237+
UNREACHABLE();
238238
}
239239
//
240240
}

src/input/game_input.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void input::GameInput::handle_event(const InputEvent event, const SimulationStep
6969
case InputEvent::HoldReleased:
7070
break;
7171
default:
72-
utils::unreachable();
72+
UNREACHABLE();
7373
}
7474
}
7575

src/input/guid.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ sdl::GUID::GUID(const SDL_GUID& data) : m_guid{} {
3434
return fmt::format("{:02x}", fmt::join(m_guid, ""));
3535
}
3636
default:
37-
utils::unreachable();
37+
UNREACHABLE();
3838
}
3939
}

0 commit comments

Comments
 (0)