1 /* { dg-options "-fdiagnostics-show-caret -Wc++-compat -std=c11" } */
2
3 /* Verify that various diagnostics show source code ranges. */
4
5 long double nanl (const char *);
6
7 /* These ones merely use token ranges; they don't use tree ranges. */
8
undeclared_identifier(void)9 void undeclared_identifier (void)
10 {
11 name; /* { dg-error "'name' undeclared .first use in this function.; did you mean .nanl." } */
12 /*
13 { dg-begin-multiline-output "" }
14 name;
15 ^~~~
16 nanl
17 { dg-end-multiline-output "" }
18 */
19 }
20
unknown_type_name(void)21 void unknown_type_name (void)
22 {
23 foo bar; /* { dg-error "unknown type name 'foo'" } */
24 /*
25 { dg-begin-multiline-output "" }
26 foo bar;
27 ^~~
28 { dg-end-multiline-output "" }
29 */
30
31 qux *baz; /* { dg-error "unknown type name 'qux'" } */
32 /*
33 { dg-begin-multiline-output "" }
34 qux *baz;
35 ^~~
36 { dg-end-multiline-output "" }
37 */
38 }
39
test_identifier_conflicts_with_cplusplus(void)40 void test_identifier_conflicts_with_cplusplus (void)
41 {
42 int new; /* { dg-warning "identifier 'new' conflicts with" } */
43 /*
44 { dg-begin-multiline-output "" }
45 int new;
46 ^~~
47 { dg-end-multiline-output "" }
48 */
49 }
50
51 extern void
52 bogus_varargs (...); /* { dg-error "ISO C requires a named argument before '...'" } */
53 /*
54 { dg-begin-multiline-output "" }
55 bogus_varargs (...);
56 ^~~
57 { dg-end-multiline-output "" }
58 */
59
60 extern void
61 foo (unknown_type param); /* { dg-error "unknown type name 'unknown_type'" } */
62 /*
63 { dg-begin-multiline-output "" }
64 foo (unknown_type param);
65 ^~~~~~~~~~~~
66 { dg-end-multiline-output "" }
67 */
68
wide_string_literal_in_asm(void)69 void wide_string_literal_in_asm (void)
70 {
71 __asm (L"nop"); /* { dg-error "wide string literal in 'asm'" } */
72 /*
73 { dg-begin-multiline-output "" }
74 __asm (L"nop");
75 ^~~~~~
76 { dg-end-multiline-output "" }
77 */
78 }
79
break_and_continue_in_wrong_places(void)80 void break_and_continue_in_wrong_places (void)
81 {
82 if (0)
83 break; /* { dg-error "break statement not within loop or switch" } */
84 /* { dg-begin-multiline-output "" }
85 break;
86 ^~~~~
87 { dg-end-multiline-output "" } */
88
89 if (1)
90 ;
91 else
92 continue; /* { dg-error "continue statement not within a loop" } */
93 /* { dg-begin-multiline-output "" }
94 continue;
95 ^~~~~~~~
96 { dg-end-multiline-output "" } */
97 }
98
99 /* Various examples of bad type decls. */
100
101 int float bogus; /* { dg-error "two or more data types in declaration specifiers" } */
102 /* { dg-begin-multiline-output "" }
103 int float bogus;
104 ^~~~~
105 { dg-end-multiline-output "" } */
106
107 long long long bogus2; /* { dg-error "'long long long' is too long for GCC" } */
108 /* { dg-begin-multiline-output "" }
109 long long long bogus2;
110 ^~~~
111 { dg-end-multiline-output "" } */
112
113 long short bogus3; /* { dg-error "both 'long' and 'short' in declaration specifiers" } */
114 /* { dg-begin-multiline-output "" }
115 long short bogus3;
116 ^~~~~
117 { dg-end-multiline-output "" } */
118
119 signed unsigned bogus4; /* { dg-error "both 'signed' and 'unsigned' in declaration specifiers" } */
120 /* { dg-begin-multiline-output "" }
121 signed unsigned bogus4;
122 ^~~~~~~~
123 { dg-end-multiline-output "" } */
124