dmd/test/fail_compilation/objc_tupleof.d
Jacob Carlborg 00761d577f Disable .offsetof/.tupleof for fields of Objective-C classes
To solve the fragile base class problem [1] in Objective-C, fields
have a dynamic offset instead of a static offset. The compiler outputs
a statically known offset which later the dynamic loader can update,
if necessary, when the application is loaded. Due to this behavior it
doesn't make sense to be able to get the offset of a field at compile
time, because this offset might not actually be the same at runtime.

To get the offset or value of a field that is correct at runtime,
functionality from the Objective-C runtime can be used instead [2].

[1] https://en.wikipedia.org/wiki/Fragile_binary_interface_problem
[2] https://developer.apple.com/documentation/objectivec/objective_c_runtime
2018-08-09 08:54:50 +02:00

17 lines
397 B
D

// EXTRA_OBJC_SOURCES
/* TEST_OUTPUT:
---
fail_compilation/objc_tupleof.d(16): Error: no property `tupleof` for type `objc_tupleof.Foo`
fail_compilation/objc_tupleof.d(16): `tupleof` is not available for members of Objective-C classes. Please use the Objective-C runtime instead
---
*/
extern (Objective-C) class Foo
{
int a;
}
void bar()
{
Foo foo;
auto a = foo.tupleof[0];
}