1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <stdio.h>
#include <string.h>
struct S {
int i;
int j;
S () {}
void g () const {}
};
void f1 (S a[1]) {}
void f2 (S *a) {}
void f3 (S (&a)[2]) {}
class C {
public:
S a[2];
char b[10];
union {
short shortVal;
int intVal;
char* stringVal;
};
union {
int blibs;
double blubs;
};
char *str () const { return (char*)b; }
};
aspect TestCopyConstructorGeneration {
advice construction ("C") : around () {
printf ("before %s\n", JoinPoint::signature ());
tjp->proceed ();
printf ("after %s\n", JoinPoint::signature ());
}
};
int main () {
printf ("ArrayWrapper: tests if wrapped arrays behave like arrays\n");
printf ("========================================================\n");
const C cc;
C c (cc);
cc.a[0];
&cc.a[0];
c.a[0];
&c.a[0];
const S *p = 0;
p = &c.a[1l];
c.a[1] = c.a[0];
c.a[0] = cc.a[0];
c.a[0].g ();
// error ...
// cc.a[0] = c.a[0];
memcpy (c.a, cc.a, sizeof (c.a));
f1 (c.a);
f2 (c.a);
// another error
// f3 (cc.a);
f3 (c.a);
&c.a;
printf ("========================================================\n");
return 0;
}
|