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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
/* run.config
STDOPT:
EXIT:1
STDOPT: +" -cpp-extra-args=-DT0"
STDOPT: +" -cpp-extra-args=-DT1"
STDOPT: +" -cpp-extra-args=-DT2"
STDOPT: +" -cpp-extra-args=-DT3"
STDOPT: +" -cpp-extra-args=-DT4"
STDOPT: +" -cpp-extra-args=-DT5"
EXIT:0
STDOPT: +" -cpp-extra-args=-DT6"
STDOPT: +" -cpp-extra-args=-DT7"
EXIT:1
STDOPT: +" -cpp-extra-args=-DT8"
*/
/* The first run is correct. The others should fail, as they include invalid
assignments to const lvalues. */
const int x = 1;
#ifdef T0
void f() {
x = 42;
}
#endif
#ifdef T1
void f() {
x++;
}
#endif
#ifdef T2
void f() {
--x;
}
#endif
#ifdef T3
void f() {
x += 3;
}
#endif
#ifdef T4
void f() {
const int x = 2;
x *= 2;
}
#endif
#ifdef T5
void f(const int* x) {
*x = 1;
}
#endif
extern void g(int *p);
#ifdef T6
void f() {
g(&x);
}
#endif
#ifdef T7
void f(const int* x) {
g(x);
}
#endif
void h(const int* x) {
int* y = (int *)x;
*y = 1;
g(y);
}
typedef struct {
__attribute__((__fc_mutable)) int x;
const int y;
} S;
void build_S(
__attribute__((__fc_initialized_object)) const S* s, int x, int y)
{
s->x = x;
s->y=y;
}
void mutable_test(const S* s) {
s->x = 42;
s->x++;
s->x += 2;
}
#ifdef T8
typedef struct {
__attribute__((__fc_mutable)) S s;
} T;
void mutable_test_ko(const T* t) {
t->s.y = 32; // KO: although t->s could be modified, t->s.y is still const
}
#endif
|