1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// test <stdio.h>
10
11#include <stdio.h>
12#include <stdarg.h>
13
14#include "test_macros.h"
15
16#ifdef getc
17#error getc is defined
18#endif
19
20#ifdef putc
21#error putc is defined
22#endif
23
24#ifdef clearerr
25#error clearerr is defined
26#endif
27
28#ifdef feof
29#error feof is defined
30#endif
31
32#ifdef ferror
33#error ferror is defined
34#endif
35
36#ifndef BUFSIZ
37#error BUFSIZ not defined
38#endif
39
40#ifndef EOF
41#error EOF not defined
42#endif
43
44#ifndef FILENAME_MAX
45#error FILENAME_MAX not defined
46#endif
47
48#ifndef FOPEN_MAX
49#error FOPEN_MAX not defined
50#endif
51
52#ifndef L_tmpnam
53#error L_tmpnam not defined
54#endif
55
56#ifndef NULL
57#error NULL not defined
58#endif
59
60#ifndef SEEK_CUR
61#error SEEK_CUR not defined
62#endif
63
64#ifndef SEEK_END
65#error SEEK_END not defined
66#endif
67
68#ifndef SEEK_SET
69#error SEEK_SET not defined
70#endif
71
72#ifndef TMP_MAX
73#error TMP_MAX not defined
74#endif
75
76#ifndef _IOFBF
77#error _IOFBF not defined
78#endif
79
80#ifndef _IOLBF
81#error _IOLBF not defined
82#endif
83
84#ifndef _IONBF
85#error _IONBF not defined
86#endif
87
88#ifndef stderr
89#error stderr not defined
90#endif
91
92#ifndef stdin
93#error stdin not defined
94#endif
95
96#ifndef stdout
97#error stdout not defined
98#endif
99
100TEST_CLANG_DIAGNOSTIC_IGNORED("-Wformat-zero-length")
101TEST_GCC_DIAGNOSTIC_IGNORED("-Wformat-zero-length")
102
103FILE* fp = 0;
104fpos_t fpos = fpos_t();
105size_t s = 0;
106char* cp = 0;
107char arr[] = {'a', 'b'};
108va_list va;
109ASSERT_SAME_TYPE(int, decltype(remove(filename: "")));
110ASSERT_SAME_TYPE(int, decltype(rename(old: "",new: "")));
111ASSERT_SAME_TYPE(FILE*, decltype(tmpfile()));
112TEST_DIAGNOSTIC_PUSH
113TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
114TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
115ASSERT_SAME_TYPE(char*, decltype(tmpnam(cp)));
116TEST_DIAGNOSTIC_POP
117ASSERT_SAME_TYPE(int, decltype(fclose(fp)));
118ASSERT_SAME_TYPE(int, decltype(fflush(fp)));
119ASSERT_SAME_TYPE(FILE*, decltype(fopen(filename: "", modes: "")));
120ASSERT_SAME_TYPE(FILE*, decltype(freopen("", "", fp)));
121ASSERT_SAME_TYPE(void, decltype(setbuf(fp,cp)));
122ASSERT_SAME_TYPE(int, decltype(vfprintf(fp,"",va)));
123ASSERT_SAME_TYPE(int, decltype(fprintf(fp," ")));
124ASSERT_SAME_TYPE(int, decltype(fscanf(fp,"")));
125ASSERT_SAME_TYPE(int, decltype(printf(format: "\n")));
126ASSERT_SAME_TYPE(int, decltype(scanf(format: "\n")));
127ASSERT_SAME_TYPE(int, decltype(snprintf(s: cp,maxlen: 0,format: "p")));
128TEST_DIAGNOSTIC_PUSH
129TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
130TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
131ASSERT_SAME_TYPE(int, decltype(sprintf(cp," ")));
132TEST_DIAGNOSTIC_POP
133ASSERT_SAME_TYPE(int, decltype(sscanf(s: "",format: "")));
134ASSERT_SAME_TYPE(int, decltype(vfprintf(fp,"",va)));
135ASSERT_SAME_TYPE(int, decltype(vfscanf(fp,"",va)));
136ASSERT_SAME_TYPE(int, decltype(vprintf(format: " ",arg: va)));
137ASSERT_SAME_TYPE(int, decltype(vscanf(format: "",arg: va)));
138ASSERT_SAME_TYPE(int, decltype(vsnprintf(s: cp,maxlen: 0,format: " ",arg: va)));
139TEST_DIAGNOSTIC_PUSH
140TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
141TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
142ASSERT_SAME_TYPE(int, decltype(vsprintf(cp," ",va)));
143TEST_DIAGNOSTIC_POP
144ASSERT_SAME_TYPE(int, decltype(vsscanf(s: "",format: "",arg: va)));
145ASSERT_SAME_TYPE(int, decltype(fgetc(fp)));
146ASSERT_SAME_TYPE(char*, decltype(fgets(cp,0,fp)));
147ASSERT_SAME_TYPE(int, decltype(fputc(0,fp)));
148ASSERT_SAME_TYPE(int, decltype(fputs("",fp)));
149ASSERT_SAME_TYPE(int, decltype(getc(fp)));
150ASSERT_SAME_TYPE(int, decltype(getchar()));
151#if TEST_STD_VER < 14
152TEST_DIAGNOSTIC_PUSH
153TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
154TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
155ASSERT_SAME_TYPE(char*, decltype(gets(cp)));
156TEST_DIAGNOSTIC_POP
157#endif
158ASSERT_SAME_TYPE(int, decltype(putc(0,fp)));
159ASSERT_SAME_TYPE(int, decltype(putchar(c: 0)));
160ASSERT_SAME_TYPE(int, decltype(puts(s: "")));
161ASSERT_SAME_TYPE(int, decltype(ungetc(0,fp)));
162ASSERT_SAME_TYPE(size_t, decltype(fread((void*)0,0,0,fp)));
163ASSERT_SAME_TYPE(size_t, decltype(fwrite((const void*)arr,1,0,fp)));
164ASSERT_SAME_TYPE(int, decltype(fgetpos(fp, &fpos)));
165ASSERT_SAME_TYPE(int, decltype(fseek(fp, 0,0)));
166ASSERT_SAME_TYPE(int, decltype(fsetpos(fp, &fpos)));
167ASSERT_SAME_TYPE(long, decltype(ftell(fp)));
168ASSERT_SAME_TYPE(void, decltype(rewind(fp)));
169ASSERT_SAME_TYPE(void, decltype(clearerr(fp)));
170ASSERT_SAME_TYPE(int, decltype(feof(fp)));
171ASSERT_SAME_TYPE(int, decltype(ferror(fp)));
172ASSERT_SAME_TYPE(void, decltype(perror(s: "")));
173

source code of libcxx/test/std/depr/depr.c.headers/stdio_h.compile.pass.cpp