1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
14 #include "test_macros.h"
17 #error getc is defined
21 #error putc is defined
25 #error clearerr is defined
29 #error feof is defined
33 #error ferror is defined
37 #error BUFSIZ not defined
41 #error EOF not defined
45 #error FILENAME_MAX not defined
49 #error FOPEN_MAX not defined
53 #error L_tmpnam not defined
57 #error NULL not defined
61 #error SEEK_CUR not defined
65 #error SEEK_END not defined
69 #error SEEK_SET not defined
73 #error TMP_MAX not defined
77 #error _IOFBF not defined
81 #error _IOLBF not defined
85 #error _IONBF not defined
89 #error stderr not defined
93 #error stdin not defined
97 #error stdout not defined
100 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wformat-zero-length")
101 TEST_GCC_DIAGNOSTIC_IGNORED("-Wformat-zero-length")
104 fpos_t fpos
= fpos_t();
107 char arr
[] = {'a', 'b'};
109 ASSERT_SAME_TYPE(int, decltype(remove("")));
110 ASSERT_SAME_TYPE(int, decltype(rename("","")));
111 ASSERT_SAME_TYPE(FILE*, decltype(tmpfile()));
113 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
114 TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
115 ASSERT_SAME_TYPE(char*, decltype(tmpnam(cp
)));
117 ASSERT_SAME_TYPE(int, decltype(fclose(fp
)));
118 ASSERT_SAME_TYPE(int, decltype(fflush(fp
)));
119 ASSERT_SAME_TYPE(FILE*, decltype(fopen("", "")));
120 ASSERT_SAME_TYPE(FILE*, decltype(freopen("", "", fp
)));
121 ASSERT_SAME_TYPE(void, decltype(setbuf(fp
,cp
)));
122 ASSERT_SAME_TYPE(int, decltype(vfprintf(fp
,"",va
)));
123 ASSERT_SAME_TYPE(int, decltype(fprintf(fp
," ")));
124 ASSERT_SAME_TYPE(int, decltype(fscanf(fp
,"")));
125 ASSERT_SAME_TYPE(int, decltype(printf("\n")));
126 ASSERT_SAME_TYPE(int, decltype(scanf("\n")));
127 ASSERT_SAME_TYPE(int, decltype(snprintf(cp
,0,"p")));
129 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
130 TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
131 ASSERT_SAME_TYPE(int, decltype(sprintf(cp
," ")));
133 ASSERT_SAME_TYPE(int, decltype(sscanf("","")));
134 ASSERT_SAME_TYPE(int, decltype(vfprintf(fp
,"",va
)));
135 ASSERT_SAME_TYPE(int, decltype(vfscanf(fp
,"",va
)));
136 ASSERT_SAME_TYPE(int, decltype(vprintf(" ",va
)));
137 ASSERT_SAME_TYPE(int, decltype(vscanf("",va
)));
138 ASSERT_SAME_TYPE(int, decltype(vsnprintf(cp
,0," ",va
)));
140 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
141 TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
142 ASSERT_SAME_TYPE(int, decltype(vsprintf(cp
," ",va
)));
144 ASSERT_SAME_TYPE(int, decltype(vsscanf("","",va
)));
145 ASSERT_SAME_TYPE(int, decltype(fgetc(fp
)));
146 ASSERT_SAME_TYPE(char*, decltype(fgets(cp
,0,fp
)));
147 ASSERT_SAME_TYPE(int, decltype(fputc(0,fp
)));
148 ASSERT_SAME_TYPE(int, decltype(fputs("",fp
)));
149 ASSERT_SAME_TYPE(int, decltype(getc(fp
)));
150 ASSERT_SAME_TYPE(int, decltype(getchar()));
151 #if TEST_STD_VER < 14
153 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
154 TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
155 ASSERT_SAME_TYPE(char*, decltype(gets(cp
)));
158 ASSERT_SAME_TYPE(int, decltype(putc(0,fp
)));
159 ASSERT_SAME_TYPE(int, decltype(putchar(0)));
160 ASSERT_SAME_TYPE(int, decltype(puts("")));
161 ASSERT_SAME_TYPE(int, decltype(ungetc(0,fp
)));
162 ASSERT_SAME_TYPE(size_t, decltype(fread((void*)0,0,0,fp
)));
163 ASSERT_SAME_TYPE(size_t, decltype(fwrite((const void*)arr
,1,0,fp
)));
164 ASSERT_SAME_TYPE(int, decltype(fgetpos(fp
, &fpos
)));
165 ASSERT_SAME_TYPE(int, decltype(fseek(fp
, 0,0)));
166 ASSERT_SAME_TYPE(int, decltype(fsetpos(fp
, &fpos
)));
167 ASSERT_SAME_TYPE(long, decltype(ftell(fp
)));
168 ASSERT_SAME_TYPE(void, decltype(rewind(fp
)));
169 ASSERT_SAME_TYPE(void, decltype(clearerr(fp
)));
170 ASSERT_SAME_TYPE(int, decltype(feof(fp
)));
171 ASSERT_SAME_TYPE(int, decltype(ferror(fp
)));
172 ASSERT_SAME_TYPE(void, decltype(perror("")));