1 /* Missing <cstddef>. */
3 void *ptr = NULL; // { dg-error "'NULL' was not declared" }
4 // { dg-message "'NULL' is defined in header '<cstddef>'; did you forget to '#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>'; did you forget to '#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>'; did you forget to '#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>'; did you forget to '#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>'; did you forget to '#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>'; did you forget to '#include <cstdio>'?" "" { target *-*-* } .-1 }
27 stderr; // { dg-error "'stderr' was not declared" }
28 // { dg-message "'stderr' is defined in header '<cstdio>'; did you forget to '#include <cstdio>'?" "" { target *-*-* } .-1 }
30 stdin; // { dg-error "'stdin' was not declared" }
31 // { dg-message "'stdin' is defined in header '<cstdio>'; did you forget to '#include <cstdio>'?" "" { target *-*-* } .-1 }
33 stdout; // { dg-error "'stdout' was not declared" }
34 // { dg-message "'stdout' is defined in header '<cstdio>'; did you forget to '#include <cstdio>'?" "" { target *-*-* } .-1 }
36 EOF; // { dg-error "'EOF' was not declared" }
37 // { dg-message "'EOF' is defined in header '<cstdio>'; did you forget to '#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>'; did you forget to '#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>'; did you forget to '#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>'; did you forget to '#include <climits>'?" "" { target *-*-* } INT_MAX_line }
80 /* Missing <cstring>. */
82 void test_cstring (char *dest, char *src)
84 memchr(dest, 'a', 4); // { dg-error "was not declared" }
85 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
86 memcmp(dest, src, 4); // { dg-error "was not declared" }
87 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
88 memcpy(dest, src, 4); // { dg-error "was not declared" }
89 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
90 memmove(dest, src, 4); // { dg-error "was not declared" }
91 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
92 memset(dest, 'a', 4); // { dg-error "was not declared" }
93 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
94 strcat(dest, "test"); // { dg-error "was not declared" }
95 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
96 strchr("test", 'e'); // { dg-error "was not declared" }
97 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
98 strcmp(dest, "test"); // { dg-error "was not declared" }
99 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
100 strcpy(dest, "test"); // { dg-error "was not declared" }
101 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
102 strlen("test"); // { dg-error "was not declared" }
103 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
104 strncat(dest, "test", 3); // { dg-error "was not declared" }
105 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
106 strncmp(dest, "test", 3); // { dg-error "was not declared" }
107 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
108 strncpy(dest, "test", 3); // { dg-error "was not declared" }
109 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
110 strrchr("test", 'e'); // { dg-error "was not declared" }
111 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
112 strspn(dest, "test"); // { dg-error "was not declared" }
113 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
114 strstr(dest, "test"); // { dg-error "was not declared" }
115 // { dg-message "'#include <cstring>'" "" { target *-*-* } .-1 }
118 /* Missing <cassert>. */
120 void test_cassert (int a, int b)
122 assert (a == b); // { dg-error "was not declared" }
123 // { dg-message "'#include <cassert>'" "" { target *-*-* } .-1 }
126 /* Missing <cstdlib>. */
128 void test_cstdlib (void *q)
130 void *ptr = malloc (64); // { dg-error "was not declared" }
131 // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
132 free (ptr); // { dg-error "was not declared" }
133 // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
134 q = realloc (q, 1024); // { dg-error "was not declared" }
135 // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
138 /* Verify that we don't offer suggestions to stdlib globals names when
139 there's an explicit namespace. */
143 int not_within_namespace (void)
145 return some_ns::stdout; // { dg-error "'stdout' is not a member of 'some_ns'" }
146 // { dg-bogus "is defined in header" "" { target *-*-* } .-1 }
149 /* Similarly for when there's an explicit class scope. */
153 int not_within_class (void)
155 return some_class::stdout; // { dg-error "'stdout' is not a member of 'some_class'" }
156 // { dg-bogus "is defined in header" "" { target *-*-* } .-1 }