The current run-time implementation is as below:
#define ASSERT_LAST_Member(Class, Member) {Class foo; assert(((size_t)(&foo) + sizeof(foo)) == ((size_t)(&foo.Member) + sizeof(foo.Member)));}
How can I do static assert while compiling? I've tried to do this, but it didn't work.
#define assert_static(e) \
do { \
enum { assert_static__ = 1/(e) }; \
} while (0)
#define ASSERT_LAST_Member(Class, Member) { assert_static(((size_t)&((Class*)0)->Member)+sizeof(((Class*)0)->Member)==sizeof(Class)) }
You can't really assert that a member is the last of its class today. The proposals in response to N3814 might make this possible, once accepted and implemented, but they're not available today. With what is currently available, you're still sunk because of padding issues (see Csq's example in the comments).
If you ignore that the limitations of padding, and limit yourself to "plain old data" cases without virtual inheritance, you can probably use the offsetof
macro, or suggestions from How to calculate offset of a class member at compile time? to perform the check you desire.
But in practice, per your comment about all your classes being protocol classes, can you not just do an assert against the known class size? It wouldn't catch cases when members were reordered, or when an addition fit within padding. But static asserts are really only there to prevent accidental incorrect changes, and you claim not to use padding. So go simple:
static_assert(sizeof(Foo) == 12, "Size of Foo has changed");