changeset 13301:ac89dbd27f78 draft

(svn r17810) -Codechange/Fix: Add assert_tcompile() and use it. OTTD's traditional assert_compile() does not work inside templates for gcc compilers, static_assert() does though. The new assert_tcompile() resolves into static_assert() if present, or into a runtime assert() else.
author frosch <frosch@openttd.org>
date Sun, 18 Oct 2009 20:26:29 +0000
parents 84f45cafda07
children eb74369706c4
files src/industry_gui.cpp src/stdafx.h
diffstat 2 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -85,7 +85,7 @@
 template <typename TC, typename TS>
 static inline void GetAllCargoSuffixes(uint cb_offset, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, const TC &cargos, TS &suffixes)
 {
-	assert_compile(lengthof(cargos) <= lengthof(suffixes));
+	assert_tcompile(lengthof(cargos) <= lengthof(suffixes));
 	for (uint j = 0; j < lengthof(cargos); j++) {
 		if (cargos[j] != CT_INVALID) {
 			GetCargoSuffix(cb_offset + j, cst, ind, ind_type, indspec, suffixes[j], lastof(suffixes[j]));
--- a/src/stdafx.h
+++ b/src/stdafx.h
@@ -301,11 +301,14 @@
 #if defined(__STDCXX_VERSION__) || defined(__GXX_EXPERIMENTAL_CXX0X__) || defined(__GXX_EXPERIMENTAL_CPP0X__) || defined(static_assert)
 	/* __STDCXX_VERSION__ is c++0x feature macro, __GXX_EXPERIMENTAL_CXX0X__ is used by gcc, __GXX_EXPERIMENTAL_CPP0X__ by icc */
 	#define assert_compile(expr) static_assert(expr, #expr )
+	#define assert_tcompile(expr) assert_compile(expr)
 #elif defined(__OS2__) || (defined(__GNUC__) && __GNUC__ == 3 && __GNUC_MINOR__ < 4)
 	/* Disabled for OS/2 or GCC < 3.4 (GCC < 3 isn't supported anymore) */
 	#define assert_compile(expr)
+	#define assert_tcompile(expr) assert(expr)
 #else
 	#define assert_compile(expr) extern const int __ct_assert__[1 - 2 * !(expr)] UNUSED
+	#define assert_tcompile(expr) assert(expr)
 #endif
 
 /* Check if the types have the bitsizes like we are using them */