1 /* Missing <cstddef>. */
3 void *ptr = NULL; // { dg-error "'NULL' was not declared" }
4 // { dg-message "'NULL' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'" "" { target *-*-* } .-1 }
6 ptrdiff_t pd; // { dg-error "'ptrdiff_t' does not name a type" }
7 // { dg-message "'ptrdiff_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'" "" { target *-*-* } .-1 }
9 size_t sz; // { dg-error "'size_t' does not name a type" }
10 // { dg-message "'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'" "" { target *-*-* } .-1 }
12 /* Missing <cstdio>. */
14 void test_cstdio (void)
16 FILE *f; // { dg-error "'FILE' was not declared in this scope" }
17 // { dg-message "'FILE' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'" "" { target *-*-* } .-1 }
18 // { dg-error "'f' was not declared in this scope" "" { target *-*-* } .-2 }
19 // { dg-bogus "suggested alternative: 'if'" "PR c++/80567" { target *-*-* } .-3 }
21 char buf[BUFSIZ]; // { dg-error "'BUFSIZ' was not declared" }
22 // { dg-message "'BUFSIZ' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'" "" { target *-*-* } .-1 }
24 char buf2[FILENAME_MAX]; // { dg-error "'FILENAME_MAX' was not declared" }
25 // { dg-message "'FILENAME_MAX' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'" "" { target *-*-* } .-1 }
27 stderr; // { dg-error "'stderr' was not declared" }
28 // { dg-message "'stderr' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'" "" { target *-*-* } .-1 }
30 stdin; // { dg-error "'stdin' was not declared" }
31 // { dg-message "'stdin' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'" "" { target *-*-* } .-1 }
33 stdout; // { dg-error "'stdout' was not declared" }
34 // { dg-message "'stdout' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'" "" { target *-*-* } .-1 }
36 EOF; // { dg-error "'EOF' was not declared" }
37 // { dg-message "'EOF' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'" "" { target *-*-* } .-1 }
39 fopen ("test.txt"); // { dg-error "'fopen' was not declared" }
40 // { dg-message "'#include <cstdio>'" "" { target *-*-* } .-1 }
42 printf ("test\n"); // { dg-error "'printf' was not declared" }
43 // { dg-message "'#include <cstdio>'" "" { target *-*-* } .-1 }
46 sprintf (tmp, "test\n"); // { dg-error "'sprintf' was not declared" }
47 // { dg-message "'#include <cstdio>'" "" { target *-*-* } .-1 }
48 snprintf (tmp, 16, "test\n"); // { dg-error "'snprintf' was not declared" }
49 // { dg-message "'#include <cstdio>'" "" { target *-*-* } .-1 }
51 getchar (); // { dg-error "'getchar' was not declared" }
52 // { dg-message "'#include <cstdio>'" "" { target *-*-* } .-1 }
55 /* Missing <cerrno>. */
57 int test_cerrno (void)
59 return errno; // { dg-error "'errno' was not declared" }
60 // { dg-message "'errno' is defined in header '<cerrno>'; this is probably fixable by adding '#include <cerrno>'" "" { target *-*-* } .-1 }
63 /* Missing <cstdarg>. */
65 void test_cstdarg (void)
67 va_list ap; // { dg-error "'va_list'" }
68 // { dg-message "'va_list' is defined in header '<cstdarg>'; this is probably fixable by adding '#include <cstdarg>'" "" { target *-*-* } .-1 }
71 /* Missing <climits>. */
72 int test_INT_MAX (void)
74 return INT_MAX; // { dg-line INT_MAX_line }
75 // { dg-error "'INT_MAX' was not declared" "" { target *-*-* } INT_MAX_line }
76 // { dg-bogus "__INT_MAX__" "" { target *-*-* } INT_MAX_line }
77 // { dg-message "'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'" "" { target *-*-* } INT_MAX_line }
80 /* Missing <cfloat>. */
81 float test_FLT_MAX = FLT_MAX; // { dg-line FLT_MAX_line }
82 // { dg-error "'FLT_MAX' was not declared" "" { target *-*-* } FLT_MAX_line }
83 // { dg-message "'FLT_MAX' is defined in header '<cfloat>'; this is probably fixable by adding '#include <cfloat>'" "" { target *-*-* } FLT_MAX_line }
85 /* Missing <cstring>. */
87 void test_cstring (char *dest, char *src)
89 memchr(dest, 'a', 4); // { dg-error "was not declared" }
90 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
91 memcmp(dest, src, 4); // { dg-error "was not declared" }
92 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
93 memcpy(dest, src, 4); // { dg-error "was not declared" }
94 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
95 memmove(dest, src, 4); // { dg-error "was not declared" }
96 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
97 memset(dest, 'a', 4); // { dg-error "was not declared" }
98 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
99 strcat(dest, "test"); // { dg-error "was not declared" }
100 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
101 strchr("test", 'e'); // { dg-error "was not declared" }
102 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
103 strcmp(dest, "test"); // { dg-error "was not declared" }
104 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
105 strcpy(dest, "test"); // { dg-error "was not declared" }
106 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
107 strerror(0); // { dg-error "was not declared" }
108 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
109 strlen("test"); // { dg-error "was not declared" }
110 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
111 strncat(dest, "test", 3); // { dg-error "was not declared" }
112 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
113 strncmp(dest, "test", 3); // { dg-error "was not declared" }
114 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
115 strncpy(dest, "test", 3); // { dg-error "was not declared" }
116 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
117 strrchr("test", 'e'); // { dg-error "was not declared" }
118 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
119 strspn(dest, "test"); // { dg-error "was not declared" }
120 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
121 strstr(dest, "test"); // { dg-error "was not declared" }
122 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
125 /* Missing <cassert>. */
127 void test_cassert (int a, int b)
129 assert (a == b); // { dg-error "was not declared" }
130 // { dg-message "'#include <cassert>'" "" { target *-*-* } .-1 }
133 /* Missing <cstdlib>. */
135 void test_cstdlib (void *q)
137 void *ptr = malloc (64); // { dg-error "was not declared" }
138 // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
139 free (ptr); // { dg-error "was not declared" }
140 // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
141 q = realloc (q, 1024); // { dg-error "was not declared" }
142 // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
143 q = calloc (8, 8); // { dg-error "was not declared" }
144 // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
147 atexit (callback); // { dg-error "was not declared" }
148 // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
150 i = EXIT_SUCCESS; // { dg-error "was not declared" }
151 // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
152 i = EXIT_FAILURE; // { dg-error "was not declared" }
153 // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
154 exit (i); // { dg-error "was not declared" }
155 // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
156 abort (); // { dg-error "was not declared" }
157 // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
159 getenv ("foo"); // { dg-error "was not declared" }
160 // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
163 /* Missing <ctime>. */
165 void test_ctime (void *q, long s, double d)
167 clock_t c; // { dg-error "was not declared" }
168 // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
169 time_t t; // { dg-error "was not declared" }
170 // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
171 tm t2; // { dg-error "was not declared" }
172 // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
173 d = difftime (0, 0); // { dg-error "was not declared" }
174 // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
175 s = mktime (q); // { dg-error "was not declared" }
176 // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
177 s = time (0); // { dg-error "was not declared" }
178 // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
179 q = asctime (0); // { dg-error "was not declared" }
180 // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
181 q = ctime (0); // { dg-error "was not declared" }
182 // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
183 q = gmtime (0); // { dg-error "was not declared" }
184 // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
185 q = localtime (0); // { dg-error "was not declared" }
186 // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
188 strftime (c, 2, "", 0); // { dg-error "was not declared" }
189 // { dg-message "'#include <ctime>'" "" { target *-*-* } .-1 }
192 /* Verify that we don't offer suggestions to stdlib globals names when
193 there's an explicit namespace. */
197 int not_within_namespace (void)
199 return some_ns::stdout; // { dg-error "'stdout' is not a member of 'some_ns'" }
200 // { dg-bogus "is defined in header" "" { target *-*-* } .-1 }
203 /* Similarly for when there's an explicit class scope. */
207 int not_within_class (void)
209 return some_class::stdout; // { dg-error "'stdout' is not a member of 'some_class'" }
210 // { dg-bogus "is defined in header" "" { target *-*-* } .-1 }