Skip to content

Commit 93e0a0e

Browse files
committed
[[ Cleanup ]] libscript: Disable offsetof warnings for pickle macros.
Officially, we're invoking undefined behaviour, but since it works for compilers that we support ignore the warnings.
1 parent a524541 commit 93e0a0e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

libscript/src/script-module.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131

3232
////////////////////////////////////////////////////////////////////////////////
3333

34+
/* Using offsetof() on a non-POD type (e.g. structs with inheritance
35+
* and classes) is, strictly-speaking, undefined according to the C++
36+
* standard (because C++'s offsetof is only present for C
37+
* compatibility and is only defined for operations on C types).
38+
* Disable GCC's offsetof warnings for these macros */
39+
#pragma GCC diagnostic push
40+
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
41+
3442
MC_PICKLE_BEGIN_RECORD(MCScriptDefinedType)
3543
MC_PICKLE_UINDEX(index)
3644
MC_PICKLE_END_RECORD()
@@ -177,6 +185,9 @@ MC_PICKLE_BEGIN_RECORD(MCScriptModule)
177185
MC_PICKLE_ARRAY_OF_RECORD(MCScriptPosition, positions, position_count)
178186
MC_PICKLE_END_RECORD()
179187

188+
/* Re-enable invalid-offsetof warnings */
189+
#pragma GCC diagnostic pop
190+
180191
////////////////////////////////////////////////////////////////////////////////
181192

182193
static MCScriptModule *s_modules = nil;

0 commit comments

Comments
 (0)