| 1 |
/* Verify that we don't emit ranges that span both |
| 2 |
a macro definition location and a macro expansion location. */ |
| 3 |
|
| 4 |
/* { dg-options "-fdiagnostics-show-caret" } */ |
| 5 |
|
| 6 |
/* Various cases involving the ranges of the LHS and RHS operands to "-". */ |
| 7 |
|
| 8 |
/* Case 1 |
| 9 |
start token is in macro definition ("&"), |
| 10 |
end token is in macro invocation ("a" and "b"). */ |
| 11 |
|
| 12 |
#define M1(A, B) &A - &B /* { dg-error "invalid operands" } */ |
| 13 |
|
| 14 |
/* Intervening |
| 15 |
material |
| 16 |
that |
| 17 |
ought |
| 18 |
not |
| 19 |
to |
| 20 |
be |
| 21 |
printed. */ |
| 22 |
|
| 23 |
int test_1 (float a, int b) |
| 24 |
{ |
| 25 |
return M1(a, b); /* { dg-message "in expansion of macro 'M1'" } */ |
| 26 |
} |
| 27 |
|
| 28 |
/* { dg-begin-multiline-output "" } |
| 29 |
#define M1(A, B) &A - &B |
| 30 |
^ |
| 31 |
{ dg-end-multiline-output "" } */ |
| 32 |
/* { dg-begin-multiline-output "" } |
| 33 |
return M1(a, b); |
| 34 |
^~ |
| 35 |
{ dg-end-multiline-output "" } */ |
| 36 |
|
| 37 |
/* Case 2: |
| 38 |
start and end tokens are both in macro invocation ("&", and "a"/"b"). */ |
| 39 |
|
| 40 |
#define M2(A, B) A - B /* { dg-error "invalid operands" } */ |
| 41 |
|
| 42 |
/* Intervening |
| 43 |
material |
| 44 |
that |
| 45 |
ought |
| 46 |
not |
| 47 |
to |
| 48 |
be |
| 49 |
printed. */ |
| 50 |
|
| 51 |
int test_2 (float a, int b) |
| 52 |
{ |
| 53 |
return M2(&a, &b); /* { dg-message "in expansion of macro 'M2'" } */ |
| 54 |
} |
| 55 |
|
| 56 |
/* { dg-begin-multiline-output "" } |
| 57 |
#define M2(A, B) A - B |
| 58 |
^ |
| 59 |
{ dg-end-multiline-output "" } */ |
| 60 |
/* { dg-begin-multiline-output "" } |
| 61 |
return M2(&a, &b); |
| 62 |
^~ |
| 63 |
{ dg-end-multiline-output "" } */ |
| 64 |
|
| 65 |
/* Case 3: |
| 66 |
start token is in macro invocation ("&"), |
| 67 |
end token is in macro definition ("a"). */ |
| 68 |
|
| 69 |
#define M3(OP) OP a - OP b /* { dg-error "invalid operands" } */ |
| 70 |
|
| 71 |
/* Intervening |
| 72 |
material |
| 73 |
that |
| 74 |
ought |
| 75 |
not |
| 76 |
to |
| 77 |
be |
| 78 |
printed. */ |
| 79 |
|
| 80 |
int test_3 (float a, int b) |
| 81 |
{ |
| 82 |
return M3(&); /* { dg-message "in expansion of macro 'M3'" } */ |
| 83 |
} |
| 84 |
|
| 85 |
/* { dg-begin-multiline-output "" } |
| 86 |
#define M3(OP) OP a - OP b |
| 87 |
^ |
| 88 |
{ dg-end-multiline-output "" } */ |
| 89 |
/* { dg-begin-multiline-output "" } |
| 90 |
return M3(&); |
| 91 |
^~ |
| 92 |
{ dg-end-multiline-output "" } */ |
| 93 |
|
| 94 |
|
| 95 |
/* Case 4: |
| 96 |
start and end tokens are both in macro definition ("&a"). */ |
| 97 |
|
| 98 |
#define M4 &a - &b /* { dg-error "invalid operands" } */ |
| 99 |
|
| 100 |
/* Intervening |
| 101 |
material |
| 102 |
that |
| 103 |
ought |
| 104 |
not |
| 105 |
to |
| 106 |
be |
| 107 |
printed. */ |
| 108 |
|
| 109 |
int test_4 (float a, int b) |
| 110 |
{ |
| 111 |
return M4; /* { dg-message "in expansion of macro 'M4'" } */ |
| 112 |
} |
| 113 |
|
| 114 |
/* { dg-begin-multiline-output "" } |
| 115 |
#define M4 &a - &b |
| 116 |
~~ ^ ~~ |
| 117 |
| | |
| 118 |
| int * |
| 119 |
float * |
| 120 |
{ dg-end-multiline-output "" } */ |
| 121 |
/* { dg-begin-multiline-output "" } |
| 122 |
return M4; |
| 123 |
^~ |
| 124 |
{ dg-end-multiline-output "" } */ |
| 125 |
|