diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 475174379d..64a08d04d6 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -1,5 +1,6 @@
add_test_files(
bitmath_func.cpp
+ enum_over_optimisation.cpp
landscape_partial_pixel_z.cpp
math_func.cpp
mock_environment.h
diff --git a/src/tests/enum_over_optimisation.cpp b/src/tests/enum_over_optimisation.cpp
new file mode 100644
index 0000000000..ef88150e64
--- /dev/null
+++ b/src/tests/enum_over_optimisation.cpp
@@ -0,0 +1,31 @@
+/*
+ * This file is part of OpenTTD.
+ * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
+ * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see .
+ */
+
+/**
+ * @file enum_over_optimisation.cpp Test whether we do not trigger an over optimisation of enums.
+ *
+ * For more details, see http://gcc.gnu.org/PR43680 and PR#5246.
+ */
+
+#include "../stdafx.h"
+
+#include "../3rdparty/catch2/catch.hpp"
+
+enum TestEnum : int8_t {
+ ZERO,
+ ONE,
+ TWO
+};
+
+TEST_CASE("EnumOverOptimisation_BoundsCheck")
+{
+ TestEnum negative_one = static_cast(-1);
+ CHECK(negative_one < ZERO);
+
+ TestEnum three = static_cast(3);
+ CHECK(TWO < three);
+}