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" } */
12 /*
13 { dg-begin-multiline-output "" }
14 name;
15 ^~~~
16 { dg-end-multiline-output "" }
17 */
18 }
19
unknown_type_name(void)20 void unknown_type_name (void)
21 {
22 foo bar; /* { dg-error "unknown type name 'foo'" } */
23 /*
24 { dg-begin-multiline-output "" }
25 foo bar;
26 ^~~
27 { dg-end-multiline-output "" }
28 */
29
30 qux *baz; /* { dg-error "unknown type name 'qux'" } */
31 /*
32 { dg-begin-multiline-output "" }
33 qux *baz;
34 ^~~
35 { dg-end-multiline-output "" }
36 */
37 }
38
test_identifier_conflicts_with_cplusplus(void)39 void test_identifier_conflicts_with_cplusplus (void)
40 {
41 int new; /* { dg-warning "identifier 'new' conflicts with" } */
42 /*
43 { dg-begin-multiline-output "" }
44 int new;
45 ^~~
46 { dg-end-multiline-output "" }
47 */
48 }
49
50 extern void
51 bogus_varargs (...); /* { dg-error "ISO C requires a named argument before '...'" } */
52 /*
53 { dg-begin-multiline-output "" }
54 bogus_varargs (...);
55 ^~~
56 { dg-end-multiline-output "" }
57 */
58
59 extern void
60 foo (unknown_type param); /* { dg-error "unknown type name 'unknown_type'" } */
61 /*
62 { dg-begin-multiline-output "" }
63 foo (unknown_type param);
64 ^~~~~~~~~~~~
65 { dg-end-multiline-output "" }
66 */
67
wide_string_literal_in_asm(void)68 void wide_string_literal_in_asm (void)
69 {
70 __asm (L"nop"); /* { dg-error "a wide string is invalid in this context" } */
71 /*
72 { dg-begin-multiline-output "" }
73 __asm (L"nop");
74 ^~~~~~
75 { dg-end-multiline-output "" }
76 */
77 }
78
break_and_continue_in_wrong_places(void)79 void break_and_continue_in_wrong_places (void)
80 {
81 if (0)
82 break; /* { dg-error "break statement not within loop or switch" } */
83 /* { dg-begin-multiline-output "" }
84 break;
85 ^~~~~
86 { dg-end-multiline-output "" } */
87
88 if (1)
89 ;
90 else
91 continue; /* { dg-error "continue statement not within a loop" } */
92 /* { dg-begin-multiline-output "" }
93 continue;
94 ^~~~~~~~
95 { dg-end-multiline-output "" } */
96 }
97
98 /* Various examples of bad type decls. */
99
100 int float bogus; /* { dg-error "two or more data types in declaration specifiers" } */
101 /* { dg-begin-multiline-output "" }
102 int float bogus;
103 ^~~~~
104 { dg-end-multiline-output "" } */
105
106 long long long bogus2; /* { dg-error "'long long long' is too long for GCC" } */
107 /* { dg-begin-multiline-output "" }
108 long long long bogus2;
109 ^~~~
110 { dg-end-multiline-output "" } */
111
112 long short bogus3; /* { dg-error "both 'long' and 'short' in declaration specifiers" } */
113 /* { dg-begin-multiline-output "" }
114 long short bogus3;
115 ^~~~~
116 { dg-end-multiline-output "" } */
117
118 signed unsigned bogus4; /* { dg-error "both 'signed' and 'unsigned' in declaration specifiers" } */
119 /* { dg-begin-multiline-output "" }
120 signed unsigned bogus4;
121 ^~~~~~~~
122 { dg-end-multiline-output "" } */
123