Remove asserts.hpp
This file seemed to be some sort of reimplementation of <cassert> except with some "feature" of trying to force the debugger to hit a breakpoint. However, any decent debugger already hits a breakpoint with a standard assert(), and this file really only served to make it harder to see the actual error when using a Windows console. Some instances of these macros were replaced with assert(), others with VALIDATE() which instead throws an exception (and possibly puts up a dialog, if the exception is caught before main()). A few other related changes that got mixed in: - Several error conditions now have a better error message (or indeed any error message at all) - Removed an unnecessary use of std::distance on a Boost iterator range. - Removed a large chunk of code which did nothing but construct a widget builder and then crash; the code was unreachable since an earlier loop did the same thing (without crashing), and the comment seems to suggest that it was a (seemingly no longer necessary) workaround for some buggy compilers / linkers. - noreturn added to the list of compatibilty C++11 features in global.hpp (Of supported compilers, only VC12 lacks the new [[attribute]] syntax.) - Fix detection of GCC in global.hpp # Conflicts: # src/gui/widgets/settings.cpp
This commit is contained in:
parent
376d45a292
commit
1816e1147f
19 changed files with 28 additions and 161 deletions
|
@ -158,7 +158,6 @@
|
|||
<Unit filename="../../src/array.hpp" />
|
||||
<Unit filename="../../src/arrow.cpp" />
|
||||
<Unit filename="../../src/arrow.hpp" />
|
||||
<Unit filename="../../src/asserts.hpp" />
|
||||
<Unit filename="../../src/attack_prediction.cpp" />
|
||||
<Unit filename="../../src/attack_prediction.hpp" />
|
||||
<Unit filename="../../src/attack_prediction_display.cpp" />
|
||||
|
|
|
@ -206,7 +206,6 @@
|
|||
<Unit filename="../../src/animated_game.cpp" />
|
||||
<Unit filename="../../src/arrow.cpp" />
|
||||
<Unit filename="../../src/arrow.hpp" />
|
||||
<Unit filename="../../src/asserts.hpp" />
|
||||
<Unit filename="../../src/attack_prediction.cpp" />
|
||||
<Unit filename="../../src/attack_prediction.hpp" />
|
||||
<Unit filename="../../src/attack_prediction_display.cpp" />
|
||||
|
|
|
@ -3988,7 +3988,6 @@
|
|||
<ClInclude Include="..\..\src\ai\testing.hpp" />
|
||||
<ClInclude Include="..\..\src\animated.hpp" />
|
||||
<ClInclude Include="..\..\src\arrow.hpp" />
|
||||
<ClInclude Include="..\..\src\asserts.hpp" />
|
||||
<ClInclude Include="..\..\src\attack_prediction.hpp" />
|
||||
<ClInclude Include="..\..\src\attack_prediction_display.hpp" />
|
||||
<ClInclude Include="..\..\src\build_info.hpp" />
|
||||
|
|
|
@ -2785,7 +2785,6 @@
|
|||
<ClInclude Include="..\..\src\about.hpp" />
|
||||
<ClInclude Include="..\..\src\animated.hpp" />
|
||||
<ClInclude Include="..\..\src\arrow.hpp" />
|
||||
<ClInclude Include="..\..\src\asserts.hpp" />
|
||||
<ClInclude Include="..\..\src\attack_prediction.hpp" />
|
||||
<ClInclude Include="..\..\src\attack_prediction_display.hpp" />
|
||||
<ClInclude Include="..\..\src\build_info.hpp" />
|
||||
|
|
|
@ -1857,7 +1857,6 @@
|
|||
B52EE89C1213590500CFBDAB /* progress_bar.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = progress_bar.hpp; sourceTree = "<group>"; };
|
||||
B52EE8A1121359A600CFBDAB /* arrow.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = arrow.cpp; sourceTree = "<group>"; };
|
||||
B52EE8A2121359A600CFBDAB /* arrow.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = arrow.hpp; sourceTree = "<group>"; };
|
||||
B52EE8A3121359A600CFBDAB /* asserts.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = asserts.hpp; sourceTree = "<group>"; };
|
||||
B52EE8A5121359A600CFBDAB /* exceptions.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = exceptions.hpp; sourceTree = "<group>"; };
|
||||
B52EE8A6121359A600CFBDAB /* debugger_fwd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = debugger_fwd.cpp; sourceTree = "<group>"; };
|
||||
B52EE8A7121359A600CFBDAB /* debugger_fwd.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = debugger_fwd.hpp; sourceTree = "<group>"; };
|
||||
|
@ -2930,7 +2929,6 @@
|
|||
B5599AB50EC62181008DD061 /* animated_game.cpp */,
|
||||
B52EE8A1121359A600CFBDAB /* arrow.cpp */,
|
||||
B52EE8A2121359A600CFBDAB /* arrow.hpp */,
|
||||
B52EE8A3121359A600CFBDAB /* asserts.hpp */,
|
||||
B5599AD00EC62181008DD061 /* attack_prediction.cpp */,
|
||||
B5599ACB0EC62181008DD061 /* attack_prediction.hpp */,
|
||||
B5599ACA0EC62181008DD061 /* attack_prediction_display.cpp */,
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 2008 by David White <dave@whitevine.net>
|
||||
2008 - 2015 by Richard Kettering <kettering.richard@gmail.com>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program 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; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ASSERTS_HPP_INCLUDED
|
||||
#define ASSERTS_HPP_INCLUDED
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <csignal>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define BREAKPOINT() __debugbreak()
|
||||
#define WES_HALT() do { BREAKPOINT(); exit(1); } while (false)
|
||||
|
||||
#elif defined(__GNUG__) && (defined(__i386__) || defined(__x86_64__)) \
|
||||
&& !defined(__native_client__)
|
||||
#define BREAKPOINT() asm("int3")
|
||||
#define WES_HALT() do { BREAKPOINT(); abort(); } while (false)
|
||||
|
||||
#elif defined(SIGTRAP)
|
||||
#define BREAKPOINT() do{ ::std::raise(SIGTRAP); } while (0)
|
||||
#define WES_HALT() do { BREAKPOINT(); abort(); } while (false)
|
||||
|
||||
#else
|
||||
#define BREAKPOINT()
|
||||
#define WES_HALT() abort()
|
||||
#endif
|
||||
|
||||
#define ERROR_LOG(a) do { \
|
||||
std::cerr << __FILE__ << ":" << __LINE__ << " ASSSERTION FAILED: " << a << std::endl; \
|
||||
WES_HALT(); \
|
||||
} while (false)
|
||||
|
||||
//for custom logging. Example usage:
|
||||
//ASSERT_LOG(x != y, "x not equal to y. Value of x: " << x << ", y: " << y);
|
||||
#define ASSERT_LOG(a,b) if (!(a)) { ERROR_LOG(b); } else (void)0
|
||||
|
||||
#define FATAL_ERROR ERROR_LOG("FATAL ERROR")
|
||||
|
||||
/**
|
||||
* Marker for code that should be unreachable.
|
||||
*
|
||||
* This can be used to avoid compiler warnings and to detect logic errors in the code.
|
||||
*/
|
||||
#define UNREACHABLE_CODE ERROR_LOG("REACHED UNREACHABLE CODE")
|
||||
|
||||
//helper macro for the simple operator cases defined below
|
||||
#define ASSERT_OP(a,op,b) ASSERT_LOG((a) op (b), #a " " #op " " #b " (" << (a) << " " #op " " << (b) << ")")
|
||||
|
||||
//various asserts of standard "equality" tests, such as "equals", "not equals", "greater than", etc.
|
||||
//Example usage ASSERT_GE(x, y);
|
||||
//on failure this will cerr "assertion failed: x >= y (value_of_x >= value_of_y)"
|
||||
#define ASSERT_EQ(a,b) ASSERT_OP(a,==,b)
|
||||
#define ASSERT_NE(a,b) ASSERT_OP(a,!=,b)
|
||||
#define ASSERT_GE(a,b) ASSERT_OP(a,>=,b)
|
||||
#define ASSERT_LE(a,b) ASSERT_OP(a,<=,b)
|
||||
#define ASSERT_GT(a,b) ASSERT_OP(a,>,b)
|
||||
#define ASSERT_LT(a,b) ASSERT_OP(a,<,b)
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
#include "editor/map/context_manager.hpp"
|
||||
|
||||
#include "asserts.hpp"
|
||||
#include "editor/action/action.hpp"
|
||||
#include "editor/action/action_unit.hpp"
|
||||
#include "editor/action/action_select.hpp"
|
||||
|
|
|
@ -68,9 +68,11 @@
|
|||
#define HAVE_INHERITING_CTORS 1
|
||||
#define CONSTEXPR constexpr
|
||||
#define NOEXCEPT noexcept
|
||||
#define NORETURN [[noreturn]]
|
||||
#else
|
||||
#define CONSTEXPR
|
||||
#define NOEXCEPT throw()
|
||||
#define NORETURN __declspec(noreturn)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -78,6 +80,8 @@
|
|||
// Clang has convenient feature detection macros \o/
|
||||
#define HAVE_REF_QUALIFIERS __has_feature(cxx_reference_qualified_functions)
|
||||
#define HAVE_INHERITING_CTORS __has_feature(cxx_inheriting_constructors)
|
||||
// All supported versions of clang have this
|
||||
#define NORETURN [[noreturn]]
|
||||
|
||||
#if __has_feature(cxx_constexpr)
|
||||
#define CONSTEXPR constexpr
|
||||
|
@ -92,14 +96,13 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__GNUX__) && !defined(__clang__)
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
// GCC supports two of these from 4.6 up and the others from 4.8 up
|
||||
#define CONSTEXPR constexpr
|
||||
#define NOEXCEPT noexcept
|
||||
#if __GNUC__ > 4 || (__GNU_C__ == 4 && __GNUC_MINOR__ >= 8)
|
||||
#define NORETURN [[noreturn]]
|
||||
#define HAVE_REF_QUALIFIERS 1
|
||||
#define HAVE_INHERITING_CTORS 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif //GLOBAL_HPP_INCLUDED
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include "gui/auxiliary/iterator/walker_grid.hpp"
|
||||
|
||||
#include "asserts.hpp"
|
||||
#include <cassert>
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "gui/auxiliary/iterator/walker_tree_node.hpp"
|
||||
#include "gui/widgets/tree_view_node.hpp"
|
||||
|
||||
#include "asserts.hpp"
|
||||
#include <cassert>
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include "gui/auxiliary/iterator/walker_widget.hpp"
|
||||
|
||||
#include "asserts.hpp"
|
||||
#include <cassert>
|
||||
#include "gui/widgets/widget.hpp"
|
||||
|
||||
namespace gui2
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include "gui/core/placer.hpp"
|
||||
|
||||
#include "asserts.hpp"
|
||||
#include <cassert>
|
||||
#include "gui/core/placer/horizontal_list.hpp"
|
||||
#include "gui/core/placer/vertical_list.hpp"
|
||||
|
||||
|
@ -34,7 +34,7 @@ tplacer_* tplacer_::build(const tgrow_direction grow_direction,
|
|||
return new implementation::tplacer_vertical_list(parallel_items);
|
||||
};
|
||||
|
||||
UNREACHABLE_CODE;
|
||||
throw "UNREACHABLE CODE REACHED";
|
||||
}
|
||||
|
||||
tplacer_::~tplacer_()
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
#include "gui/core/window_builder.hpp"
|
||||
|
||||
#include "asserts.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "gui/core/log.hpp"
|
||||
#include "gui/core/window_builder/helper.hpp"
|
||||
|
@ -155,8 +154,7 @@ register_builder_widget(const std::string& id,
|
|||
tbuilder_widget_ptr create_builder_widget(const config& cfg)
|
||||
{
|
||||
config::const_all_children_itors children = cfg.all_children_range();
|
||||
size_t nb_children = std::distance(children.begin(), children.end());
|
||||
VALIDATE(nb_children == 1, "Grid cell does not have exactly 1 child.");
|
||||
VALIDATE(children.size() == 1, "Grid cell does not have exactly 1 child.");
|
||||
|
||||
for(const auto & item : builder_widget_lookup())
|
||||
{
|
||||
|
@ -184,54 +182,8 @@ tbuilder_widget_ptr create_builder_widget(const config& cfg)
|
|||
return std::make_shared<implementation::tbuilder_viewport>(viewport);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is rather odd, when commented out the classes no longer seem to be in
|
||||
* the executable, no real idea why, except maybe of an overzealous optimizer
|
||||
* while linking. It seems that all these classes aren't explicitly
|
||||
* instantiated but only implicitly. Also when looking at the symbols in
|
||||
* libwesnoth-game.a the repeating button is there regardless of this #if but
|
||||
* in the final binary only if the #if is enabled.
|
||||
*
|
||||
* If this code is executed, which it will cause an assertion failure.
|
||||
*
|
||||
* Its likeley that this happens becasue some build this as a library file
|
||||
* which is then used by the wesnoth executable. For msvc a good try to fix
|
||||
* this issue is to add __pragma(comment(linker, "/include:" #TYPE)) or
|
||||
* similar in the REGISTER_WIDGET3 macro. For gcc and similar this can only
|
||||
* be fixed by using --whole-archive flag when linking this library.
|
||||
*/
|
||||
#if 1
|
||||
#define TRY(name) \
|
||||
do { \
|
||||
if(const config& c = cfg.child(#name)) { \
|
||||
tbuilder_widget_ptr p = \
|
||||
std::make_shared<implementation::tbuilder_##name>(c); \
|
||||
assert(false); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
TRY(stacked_widget);
|
||||
TRY(scrollbar_panel);
|
||||
TRY(horizontal_scrollbar);
|
||||
TRY(repeating_button);
|
||||
TRY(vertical_scrollbar);
|
||||
TRY(label);
|
||||
TRY(image);
|
||||
TRY(toggle_button);
|
||||
TRY(slider);
|
||||
TRY(scroll_label);
|
||||
TRY(matrix);
|
||||
TRY(minimap);
|
||||
TRY(button);
|
||||
TRY(menu_button);
|
||||
TRY(drawing);
|
||||
TRY(password_box);
|
||||
TRY(unit_preview_pane);
|
||||
#undef TRY
|
||||
#endif
|
||||
|
||||
std::cerr << cfg;
|
||||
ERROR_LOG(false);
|
||||
VALIDATE(false,"Unknown widget type " + cfg.ordered_begin()->key);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*WIKI
|
||||
|
|
|
@ -17,12 +17,13 @@
|
|||
|
||||
#include "gui/widgets/generator.hpp"
|
||||
|
||||
#include "asserts.hpp"
|
||||
#include <cassert>
|
||||
#include "gui/widgets/grid.hpp"
|
||||
#include "gui/widgets/selectable.hpp"
|
||||
#include "gui/widgets/toggle_button.hpp"
|
||||
#include "gui/widgets/toggle_panel.hpp"
|
||||
#include "gui/widgets/window.hpp" // For twindow::tvisible
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
@ -696,7 +697,8 @@ public:
|
|||
return i;
|
||||
}
|
||||
}
|
||||
ERROR_LOG("No item selected.");
|
||||
VALIDATE_WITH_DEV_MESSAGE(false, "No item selected.",
|
||||
"selected_item_count_ was non-zero, yet no selected item was found.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#include "gui/widgets/settings.hpp"
|
||||
|
||||
#include "asserts.hpp"
|
||||
#include "formatter.hpp"
|
||||
#include "config_cache.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "gettext.hpp"
|
||||
|
@ -625,8 +625,7 @@ tresolution_definition_ptr get_control(const std::string& control_type,
|
|||
auto default_control_definition = default_gui->second.control_definition.find(control_type);
|
||||
#endif
|
||||
|
||||
ASSERT_LOG(default_control_definition != default_gui->second.control_definition.end(),
|
||||
"Type '" << control_type << "' is unknown.");
|
||||
VALIDATE(control_definition != current_gui->second.control_definition.end(), formatter() << "Type '" << control_type << "' is unknown.");
|
||||
|
||||
control = default_control_definition->second.find(definition);
|
||||
found_fallback = control != default_control_definition->second.end();
|
||||
|
@ -656,7 +655,7 @@ tresolution_definition_ptr get_control(const std::string& control_type,
|
|||
}
|
||||
}
|
||||
|
||||
ERROR_LOG(false);
|
||||
VALIDATE(false, formatter() << "Control: type '" << control_type << "' definition '" << definition << "' has no resolutions.\n");
|
||||
}
|
||||
|
||||
std::vector<twindow_builder::tresolution>::const_iterator
|
||||
|
@ -693,7 +692,7 @@ get_window_builder(const std::string& type)
|
|||
}
|
||||
}
|
||||
|
||||
ERROR_LOG(false);
|
||||
VALIDATE(false, formatter() << "Window '" << type << "' has no resolutions.\n");
|
||||
}
|
||||
|
||||
/*WIKI
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "storyscreen/part.hpp"
|
||||
#include "storyscreen/render.hpp"
|
||||
|
||||
#include "asserts.hpp"
|
||||
#include <cassert>
|
||||
#include "variable.hpp"
|
||||
|
||||
#include "game_events/conditional_wml.hpp"
|
||||
|
@ -50,7 +50,7 @@ controller::controller(CVideo& video, const vconfig& data, const std::string& sc
|
|||
, segment_index_(segment_index)
|
||||
, parts_()
|
||||
{
|
||||
ASSERT_LOG(resources::gamedata != nullptr, "Ouch: gamedata is nullptr when initializing storyscreen controller");
|
||||
assert(resources::gamedata != nullptr && "Ouch: gamedata is nullptr when initializing storyscreen controller");
|
||||
resolve_wml(data);
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,7 @@ STORY_RESULT controller::show(START_POSITION startpos)
|
|||
#ifndef LOW_MEM
|
||||
std::vector< render_pointer_type > uis_;
|
||||
for(part_pointer_type p : parts_) {
|
||||
ASSERT_LOG( p != nullptr, "Ouch: hit nullptr storyscreen part in collection" );
|
||||
assert(p != nullptr && "Ouch: hit nullptr storyscreen part in collection");
|
||||
render_pointer_type const rpt(new part_ui(*p, video_, next_button, back_button, play_button));
|
||||
uis_.push_back(rpt);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
|
||||
#include "global.hpp"
|
||||
#include "asserts.hpp"
|
||||
#include "log.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "storyscreen/part.hpp"
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
|
||||
#include "global.hpp"
|
||||
#include "asserts.hpp"
|
||||
#include <cassert>
|
||||
#include "log.hpp"
|
||||
#include "storyscreen/part.hpp"
|
||||
#include "storyscreen/render.hpp"
|
||||
|
@ -255,7 +255,7 @@ void part_ui::prepare_background()
|
|||
}
|
||||
|
||||
blit_surface(layer, &srect, background_, &drect);
|
||||
ASSERT_LOG(layer.null() == false, "Oops: a storyscreen part background layer got nullptr");
|
||||
assert(layer.null() == false && "Oops: a storyscreen part background layer got nullptr");
|
||||
|
||||
if (bl.is_base_layer() || no_base_yet) {
|
||||
x_scale_factor_ = x_scale_factor;
|
||||
|
|
|
@ -62,9 +62,6 @@ class CVideo;
|
|||
#define FAIL(message) \
|
||||
do { \
|
||||
wml_exception(nullptr, __FILE__, __LINE__, __func__, message); \
|
||||
/* wml_exception never returns. */ \
|
||||
/* Help the compiler to figure that out */ \
|
||||
throw 42; \
|
||||
} while(0)
|
||||
|
||||
#define FAIL_WITH_DEV_MESSAGE(message, dev_message) \
|
||||
|
@ -75,9 +72,6 @@ class CVideo;
|
|||
, __func__ \
|
||||
, message \
|
||||
, dev_message); \
|
||||
/* wml_exception never returns. */ \
|
||||
/* Help the compiler to figure that out */ \
|
||||
throw 42; \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
|
@ -89,7 +83,7 @@ class CVideo;
|
|||
* @param function The function in which the test failed.
|
||||
* @param message The translated message to show the user.
|
||||
*/
|
||||
void wml_exception(
|
||||
NORETURN void wml_exception(
|
||||
const char* cond
|
||||
, const char* file
|
||||
, int line
|
||||
|
|
Loading…
Add table
Reference in a new issue