| 1 |
/* { dg-do compile } */ |
| 2 |
|
| 3 |
/* See the notes in diagnostic-test-string-literals-1.c. |
| 4 |
This test case has caret-printing disabled. */ |
| 5 |
|
| 6 |
extern void __emit_string_literal_range (const void *literal, int caret_idx, |
| 7 |
int start_idx, int end_idx); |
| 8 |
/* Test of a stringified macro argument, by itself. */ |
| 9 |
|
| 10 |
void |
| 11 |
test_stringified_token_1 (int x) |
| 12 |
{ |
| 13 |
#define STRINGIFY(EXPR) #EXPR |
| 14 |
|
| 15 |
__emit_string_literal_range (STRINGIFY(x > 0), /* { dg-error "macro expansion|cpp_interpret_string_1 failed" } */ |
| 16 |
0, 0, 4); |
| 17 |
|
| 18 |
#undef STRINGIFY |
| 19 |
} |
| 20 |
|
| 21 |
/* Test of a stringified token within a concatenation. */ |
| 22 |
|
| 23 |
void |
| 24 |
test_stringized_token_2 (int x) |
| 25 |
{ |
| 26 |
#define EXAMPLE(EXPR, CARET_IDX, START_IDX, END_IDX) \ |
| 27 |
do { \ |
| 28 |
__emit_string_literal_range (" before " #EXPR " after \n", \ |
| 29 |
CARET_IDX, START_IDX, END_IDX); \ |
| 30 |
} while (0) |
| 31 |
|
| 32 |
EXAMPLE(x > 0, 1, 1, 6); |
| 33 |
/* { dg-error "unable to read substring location: cpp_interpret_string_1 failed" "" { target *-*-* } .-5 } */ |
| 34 |
|
| 35 |
#undef EXAMPLE |
| 36 |
} |
| 37 |
|
| 38 |
/* Test of a doubly-stringified macro argument (by itself). */ |
| 39 |
|
| 40 |
void |
| 41 |
test_stringified_token_3 (int x) |
| 42 |
{ |
| 43 |
#define XSTR(s) STR(s) |
| 44 |
#define STR(s) #s |
| 45 |
#define FOO 123456789 |
| 46 |
__emit_string_literal_range (XSTR (FOO), /* { dg-error "macro expansion|cpp_interpret_string_1 failed" } */ |
| 47 |
2, 2, 3); |
| 48 |
|
| 49 |
#undef XSTR |
| 50 |
#undef STR |
| 51 |
#undef FOO |
| 52 |
} |
| 53 |
|
| 54 |
/* Test of a stringified macro argument within a concatenation. */ |
| 55 |
|
| 56 |
void |
| 57 |
test_pr79210 (void) |
| 58 |
{ |
| 59 |
#define lpfc_vport_param_init(attr) \ |
| 60 |
__emit_string_literal_range ( \ |
| 61 |
"0423 lpfc_"#attr" attribute cannot be set to %d, "\ |
| 62 |
"allowed range is [0, 1]\n", 54, 53, 54) \ |
| 63 |
|
| 64 |
#define LPFC_VPORT_ATTR_R(name, decc) \ |
| 65 |
unsigned int lpfc_##name; \ |
| 66 |
lpfc_vport_param_init(name) \ |
| 67 |
|
| 68 |
LPFC_VPORT_ATTR_R(peer_port_login, |
| 69 |
"some multiline blurb with a short final line " |
| 70 |
"here"); |
| 71 |
|
| 72 |
/* { dg-error "19: unable to read substring location: range endpoints are on different lines" "" { target c } .-11 } */ |
| 73 |
/* { dg-error "19: unable to read substring location: line is not wide enough" "" { target c++ } .-12 } */ |
| 74 |
|
| 75 |
#undef LPFC_VPORT_ATTR_R |
| 76 |
#undef lpfc_vport_param_init |
| 77 |
} |