Commit 7bf94db3 by Mark Mitchell

Add data member test

From-SVN: r32108
parent fa2e34e8
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
struct S struct S
{ {
int i; int i;
int j;
}; };
// Because S does not have a VPTR, it will not be a primary base of T, // Because S does not have a VPTR, it will not be a primary base of T,
...@@ -37,12 +38,14 @@ struct ptrmemfunc ...@@ -37,12 +38,14 @@ struct ptrmemfunc
ptrdiff_t adj; ptrdiff_t adj;
}; };
typedef int S::*sdp;
typedef void (S::*sp)(); typedef void (S::*sp)();
typedef void (T::*tp)(); typedef void (T::*tp)();
int int
main () main ()
{ {
S s;
T t; T t;
sp x; sp x;
tp y; tp y;
...@@ -50,8 +53,8 @@ main () ...@@ -50,8 +53,8 @@ main ()
ptrmemfunc *yp = (ptrmemfunc *) &y; ptrmemfunc *yp = (ptrmemfunc *) &y;
ptrdiff_t delta = ((char *) &t) - ((char*) (S*) (&t)); ptrdiff_t delta = ((char *) &t) - ((char*) (S*) (&t));
// Pointers-to-members should have the same size and alignment as // Pointers-to-function-members should have the same size and
// the PTRMEMFUNC type. // alignment as the PTRMEMFUNC type.
if (sizeof (sp) != sizeof (ptrmemfunc)) if (sizeof (sp) != sizeof (ptrmemfunc))
return 1; return 1;
if (__alignof__ (sp) != __alignof__ (ptrmemfunc)) if (__alignof__ (sp) != __alignof__ (ptrmemfunc))
...@@ -92,6 +95,17 @@ main () ...@@ -92,6 +95,17 @@ main ()
return 11; return 11;
if (xp->adj != delta) if (xp->adj != delta)
return 12; return 12;
// Pointers-to-data-members should have the same size and alignment
// as a ptrdiff_t.
if (sizeof (sdp) != sizeof (ptrdiff_t))
return 13;
if (__alignof__ (sdp) != __alignof__ (ptrdiff_t))
return 14;
sdp z = &S::j;
if ((char *) &s.j - (char *) &s != *((ptrdiff_t *) &z) - 1)
return 15;
} }
#else /* !(defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100) */ #else /* !(defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100) */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment