widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #01263
[Merge] lp:~widelands-dev/widelands/boost_static_assert into lp:widelands
cghislai has proposed merging lp:~widelands-dev/widelands/boost_static_assert into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/boost_static_assert/+merge/175607
This get rid of compile_assert.h in favor of the BOOST_STATIC_ASSERT macro provided with boost.
The former version produced a lot of warnings with my compiler, while the later provides the most elegant solution depending on the platform and compiler.
the macro can be viewed here : http://www.boost.org/doc/libs/1_54_0/boost/static_assert.hpp
--
https://code.launchpad.net/~widelands-dev/widelands/boost_static_assert/+merge/175607
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/boost_static_assert into lp:widelands.
=== removed file 'src/compile_assert.h'
--- src/compile_assert.h 2013-02-10 18:47:18 +0000
+++ src/compile_assert.h 1970-01-01 00:00:00 +0000
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2006 by the Widelands Development Team
- *
- * 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; 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef compile_assert
-// gnu needs to append a unique number to the assert, otherwise it complains
-// about this shadowing the last assert. This is not too easy, so we use the
-// line number - collisions are not that probable anymore.
-// The concatenation magic is from: http://stackoverflow.com/a/1597129/200945
-#define TOKENPASTE(x, y) x ## y
-#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
-#define compile_assert(x) typedef bool TOKENPASTE2(COMPILE_ASSERT_, __LINE__)[(x) ? 1 : -1]
-#endif
=== modified file 'src/graphic/render/gamerenderer_gl.cc'
--- src/graphic/render/gamerenderer_gl.cc 2013-07-13 14:32:49 +0000
+++ src/graphic/render/gamerenderer_gl.cc 2013-07-18 15:21:32 +0000
@@ -233,7 +233,7 @@
void GameRendererGL::prepare_terrain_base()
{
- compile_assert(sizeof(basevertex) == 32);
+ BOOST_STATIC_ASSERT(sizeof(basevertex) == 32);
uint32_t reqsize = m_patch_size.w * m_patch_size.h;
if (reqsize > 0x10000)
@@ -408,7 +408,7 @@
*/
void GameRendererGL::prepare_terrain_dither()
{
- compile_assert(sizeof(dithervertex) == 32);
+ BOOST_STATIC_ASSERT(sizeof(dithervertex) == 32);
if (m_terrain_edge_freq.size() < 16)
m_terrain_edge_freq.resize(16);
=== modified file 'src/io/bitinbuffer.h'
--- src/io/bitinbuffer.h 2012-09-21 21:36:07 +0000
+++ src/io/bitinbuffer.h 2013-07-18 15:21:32 +0000
@@ -22,7 +22,7 @@
#include "fileread.h"
-#include "compile_assert.h"
+#include <boost/static_assert.hpp>
/// Wrapper around FileRead for reading groups of Size bits from a file, where
/// Size can be a factor of 8. Call get to read Size bits from the buffer.
@@ -30,7 +30,7 @@
/// the file was created will not fail unless it causes another byte to be read
/// from the file.
template<uint8_t const Size> struct BitInBuffer {
- compile_assert(Size == 1 or Size == 2 or Size == 4);
+ BOOST_STATIC_ASSERT(Size == 1 or Size == 2 or Size == 4);
BitInBuffer() : buffer(0), mask(0x00) {}
void Open(FileSystem & fs, char const * const filename) {
fr.Open(fs, filename);
=== modified file 'src/io/bitoutbuffer.h'
--- src/io/bitoutbuffer.h 2012-02-15 21:25:34 +0000
+++ src/io/bitoutbuffer.h 2013-07-18 15:21:32 +0000
@@ -22,13 +22,13 @@
#include "filewrite.h"
-#include "compile_assert.h"
+#include <boost/static_assert.hpp>
/// Wrapper around FileWrite for writing bits to a file. Call put to write a
/// bit to the buffer. Call Write to write the buffer to file. Unassigned bits
/// in the last byte will be 0.
template<uint8_t const Size> struct BitOutBuffer {
- compile_assert(Size == 1 or Size == 2 or Size == 4);
+ BOOST_STATIC_ASSERT(Size == 1 or Size == 2 or Size == 4);
BitOutBuffer() : buffer(0x00), mask(0xff) {}
void put(uint8_t const item) {
assert(item < (1 << Size));
=== modified file 'src/logic/constructionsite.cc'
--- src/logic/constructionsite.cc 2013-07-15 05:18:12 +0000
+++ src/logic/constructionsite.cc 2013-07-18 15:21:32 +0000
@@ -345,7 +345,7 @@
// Draw the partially finished building
- compile_assert(0 <= CONSTRUCTIONSITE_STEP_TIME);
+ BOOST_STATIC_ASSERT(0 <= CONSTRUCTIONSITE_STEP_TIME);
m_info.totaltime = CONSTRUCTIONSITE_STEP_TIME * m_work_steps;
m_info.completedtime = CONSTRUCTIONSITE_STEP_TIME * m_work_completed;
=== modified file 'src/logic/dismantlesite.cc'
--- src/logic/dismantlesite.cc 2013-07-15 05:18:12 +0000
+++ src/logic/dismantlesite.cc 2013-07-18 15:21:32 +0000
@@ -247,7 +247,7 @@
dst.drawanim(pos, m_anim, tanim, get_owner());
// Draw the partially dismantled building
- compile_assert(0 <= DISMANTLESITE_STEP_TIME);
+ BOOST_STATIC_ASSERT(0 <= DISMANTLESITE_STEP_TIME);
uint32_t total_time = DISMANTLESITE_STEP_TIME * m_work_steps;
uint32_t completed_time = DISMANTLESITE_STEP_TIME * m_work_completed;
=== modified file 'src/logic/field.h'
--- src/logic/field.h 2013-07-14 10:43:19 +0000
+++ src/logic/field.h 2013-07-18 15:21:32 +0000
@@ -21,7 +21,7 @@
#define FIELD_H
#include "widelands_geometry.h"
-#include "compile_assert.h"
+#include <boost/static_assert.hpp>
#include "constants.h"
#include "nodecaps.h"
#include "world.h"
@@ -79,11 +79,11 @@
typedef uint8_t Resource_Amount;
struct Terrains {Terrain_Index d : 4, r : 4;};
- compile_assert(sizeof(Terrains) == 1);
+ BOOST_STATIC_ASSERT(sizeof(Terrains) == 1);
struct Resources {Resource_Index d : 4, r : 4;};
- compile_assert(sizeof(Resources) == 1);
+ BOOST_STATIC_ASSERT(sizeof(Resources) == 1);
struct Resource_Amounts {Resource_Amount d : 4, r : 4;};
- compile_assert(sizeof(Resource_Amounts) == 1);
+ BOOST_STATIC_ASSERT(sizeof(Resource_Amounts) == 1);
private:
/**
@@ -110,7 +110,7 @@
Border_Bitmask - 1;
static const Owner_Info_and_Selections_Type Owner_Info_Bitmask =
Player_Number_Bitmask + Border_Bitmask;
- compile_assert(MAX_PLAYERS <= Player_Number_Bitmask);
+ BOOST_STATIC_ASSERT(MAX_PLAYERS <= Player_Number_Bitmask);
// Data Members
/** linked list, \sa Bob::m_linknext*/
@@ -236,7 +236,7 @@
#pragma pack(pop)
// Check that Field is tightly packed.
-compile_assert(sizeof(Field) <= sizeof(void *) * 2 + 10);
+BOOST_STATIC_ASSERT(sizeof(Field) <= sizeof(void *) * 2 + 10);
}
#endif
=== modified file 'src/logic/widelands_geometry.h'
--- src/logic/widelands_geometry.h 2013-04-25 07:27:14 +0000
+++ src/logic/widelands_geometry.h 2013-07-18 15:21:32 +0000
@@ -20,7 +20,7 @@
#ifndef WIDELANDS_GEOMETRY_H
#define WIDELANDS_GEOMETRY_H
-#include "compile_assert.h"
+#include <boost/static_assert.hpp>
#include <cmath>
#include <stdint.h>
@@ -82,7 +82,7 @@
union {struct {X_Coordinate x; Y_Coordinate y;}; uint32_t all;};
};
-compile_assert(sizeof(Coords) == 4);
+BOOST_STATIC_ASSERT(sizeof(Coords) == 4);
template <typename _Coords_type = Coords, typename _Radius_type = uint16_t>
struct Area : public _Coords_type
=== modified file 'src/map_io/widelands_map_exploration_data_packet.cc'
--- src/map_io/widelands_map_exploration_data_packet.cc 2013-02-10 19:36:24 +0000
+++ src/map_io/widelands_map_exploration_data_packet.cc 2013-07-18 15:21:32 +0000
@@ -54,7 +54,7 @@
}
}
- compile_assert(MAX_PLAYERS < 32);
+ BOOST_STATIC_ASSERT(MAX_PLAYERS < 32);
Map & map = egbase.map();
Player_Number const nr_players = map.get_nrplayers();
Map_Index const max_index = map.max_index();
@@ -105,7 +105,7 @@
fw.Unsigned16(CURRENT_PACKET_VERSION);
- compile_assert(MAX_PLAYERS < 32);
+ BOOST_STATIC_ASSERT(MAX_PLAYERS < 32);
Map & map = egbase.map();
Player_Number const nr_players = map.get_nrplayers();
Map_Index const max_index = map.max_index();
=== modified file 'src/scripting/pluto.cc'
--- src/scripting/pluto.cc 2013-07-18 05:40:10 +0000
+++ src/scripting/pluto.cc 2013-07-18 15:21:32 +0000
@@ -598,7 +598,7 @@
/* Serialize code */
{
- compile_assert(sizeof(Instruction) == 4);
+ BOOST_STATIC_ASSERT(sizeof(Instruction) == 4);
pi->fw->Signed32(p->sizecode);
for (int32_t i = 0; i < p->sizecode; i++)
pi->fw->Unsigned32(p->code[i]);
=== modified file 'src/ui_basic/checkbox.cc'
--- src/ui_basic/checkbox.cc 2013-02-10 19:36:24 +0000
+++ src/ui_basic/checkbox.cc 2013-07-18 15:21:32 +0000
@@ -22,7 +22,7 @@
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
-#include "compile_assert.h"
+#include <boost/static_assert.hpp>
namespace UI {
/**
@@ -117,8 +117,8 @@
dst.draw_rect
(Rect(Point(0, 0), get_w(), get_h()), RGBColor(100, 100, 80));
} else {
- compile_assert(0 <= STATEBOX_WIDTH);
- compile_assert(0 <= STATEBOX_HEIGHT);
+ BOOST_STATIC_ASSERT(0 <= STATEBOX_WIDTH);
+ BOOST_STATIC_ASSERT(0 <= STATEBOX_HEIGHT);
dst.blitrect
(Point(0, 0),
m_pic_graphics,
=== modified file 'src/ui_basic/listselect.h'
--- src/ui_basic/listselect.h 2013-06-15 14:08:10 +0000
+++ src/ui_basic/listselect.h 2013-07-18 15:21:32 +0000
@@ -27,7 +27,7 @@
#include <boost/signal.hpp>
#include "align.h"
-#include "compile_assert.h"
+#include <boost/static_assert.hpp>
#include "panel.h"
#include "rgbcolor.h"
=== modified file 'src/ui_basic/table.h'
--- src/ui_basic/table.h 2013-02-10 19:36:24 +0000
+++ src/ui_basic/table.h 2013-07-18 15:21:32 +0000
@@ -28,7 +28,7 @@
#include <boost/signal.hpp>
#include "align.h"
-#include "compile_assert.h"
+#include <boost/static_assert.hpp>
#include "rgbcolor.h"
#include "panel.h"
@@ -402,7 +402,7 @@
}
};
-compile_assert(sizeof(void *) == sizeof(uintptr_t));
+BOOST_STATIC_ASSERT(sizeof(void *) == sizeof(uintptr_t));
template <> class Table<uintptr_t> : public Table<void *> {
public:
typedef Table<void *> Base;
=== modified file 'src/ui_basic/tabpanel.cc'
--- src/ui_basic/tabpanel.cc 2013-02-10 19:36:24 +0000
+++ src/ui_basic/tabpanel.cc 2013-07-18 15:21:32 +0000
@@ -23,7 +23,7 @@
#include "graphic/rendertarget.h"
-#include "compile_assert.h"
+#include <boost/static_assert.hpp>
namespace UI {
#define TP_BUTTON_WIDTH 34
@@ -205,8 +205,8 @@
uint32_t x;
// draw the background
- compile_assert(2 < TP_BUTTON_WIDTH);
- compile_assert(4 < TP_BUTTON_HEIGHT);
+ BOOST_STATIC_ASSERT(2 < TP_BUTTON_WIDTH);
+ BOOST_STATIC_ASSERT(4 < TP_BUTTON_HEIGHT);
if (m_pic_background) {
dst.tile
=== modified file 'src/ui_basic/window.cc'
--- src/ui_basic/window.cc 2013-02-10 19:36:24 +0000
+++ src/ui_basic/window.cc 2013-07-18 15:21:32 +0000
@@ -28,7 +28,7 @@
#include "text_layout.h"
#include "wlapplication.h"
-#include "compile_assert.h"
+#include <boost/static_assert.hpp>
#include <SDL_keysym.h>
@@ -299,7 +299,7 @@
Rect(Point(0, 0), pos, TP_B_PIXMAP_THICKNESS));
// top bar
- compile_assert(0 <= HZ_B_CORNER_PIXMAP_LEN);
+ BOOST_STATIC_ASSERT(0 <= HZ_B_CORNER_PIXMAP_LEN);
for (; pos < hz_bar_end_minus_middle; pos += HZ_B_MIDDLE_PIXMAP_LEN)
dst.blitrect
(Point(pos, 0),
@@ -336,7 +336,7 @@
{ // Left border
- compile_assert(0 <= VT_B_PIXMAP_THICKNESS);
+ BOOST_STATIC_ASSERT(0 <= VT_B_PIXMAP_THICKNESS);
dst.blitrect // left top thingy
(Point(0, TP_B_PIXMAP_THICKNESS),
m_pic_lborder,
@@ -345,7 +345,7 @@
int32_t pos = TP_B_PIXMAP_THICKNESS + VT_B_THINGY_PIXMAP_LEN;
// left bar
- compile_assert(0 <= VT_B_THINGY_PIXMAP_LEN);
+ BOOST_STATIC_ASSERT(0 <= VT_B_THINGY_PIXMAP_LEN);
for (; pos < vt_bar_end_minus_middle; pos += VT_B_MIDDLE_PIXMAP_LEN)
dst.blitrect
(Point(0, pos),
@@ -377,7 +377,7 @@
int32_t pos = TP_B_PIXMAP_THICKNESS + VT_B_THINGY_PIXMAP_LEN;
// right bar
- compile_assert(0 <= VT_B_THINGY_PIXMAP_LEN);
+ BOOST_STATIC_ASSERT(0 <= VT_B_THINGY_PIXMAP_LEN);
for (; pos < vt_bar_end_minus_middle; pos += VT_B_MIDDLE_PIXMAP_LEN)
dst.blitrect
(Point(right_border_x, pos),
=== modified file 'src/vector.h'
--- src/vector.h 2012-07-13 20:46:30 +0000
+++ src/vector.h 2013-07-18 15:21:32 +0000
@@ -20,7 +20,7 @@
#ifndef VECTOR_H
#define VECTOR_H
-#include "compile_assert.h"
+#include <boost/static_assert.hpp>
#include <cmath>
=== modified file 'src/wlapplication.cc'
--- src/wlapplication.cc 2013-07-16 14:05:48 +0000
+++ src/wlapplication.cc 2013-07-18 15:21:32 +0000
@@ -1660,7 +1660,7 @@
{
// This is the code returned by UI::Panel::run() when the panel is dying.
// Make sure that the program exits when the window manager says so.
- compile_assert(Fullscreen_Menu_SinglePlayer::Back == UI::Panel::dying_code);
+ BOOST_STATIC_ASSERT(Fullscreen_Menu_SinglePlayer::Back == UI::Panel::dying_code);
for (;;) {
int32_t code;
@@ -1775,7 +1775,7 @@
{
// This is the code returned by UI::Panel::run() when the panel is dying.
// Make sure that the program exits when the window manager says so.
- compile_assert(Fullscreen_Menu_Editor::Back == UI::Panel::dying_code);
+ BOOST_STATIC_ASSERT(Fullscreen_Menu_Editor::Back == UI::Panel::dying_code);
for (;;) {
int32_t code;
=== modified file 'src/wui/encyclopedia_window.cc'
--- src/wui/encyclopedia_window.cc 2013-02-10 19:36:24 +0000
+++ src/wui/encyclopedia_window.cc 2013-07-18 15:21:32 +0000
@@ -203,7 +203,7 @@
// Make sure to detect if someone changes the type so that it
// needs more than 3 decimal digits to represent.
- compile_assert
+ BOOST_STATIC_ASSERT
(only1byte<sizeof(j.current->second)>::result);
char amount_string[4]; // Space for 3 digits + terminator.
sprintf(amount_string, "%u", j.current->second);
Follow ups