Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // test <stdio.h> |
| 10 | |
| 11 | #include <stdio.h> |
| 12 | #include <type_traits> |
Eric Fiselier | 203f687 | 2015-07-18 22:51:51 +0000 | [diff] [blame] | 13 | #include "test_macros.h" |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 14 | |
Richard Smith | d328274 | 2015-10-09 01:29:09 +0000 | [diff] [blame] | 15 | #ifdef getc |
| 16 | #error getc is defined |
| 17 | #endif |
| 18 | |
| 19 | #ifdef putc |
| 20 | #error putc is defined |
| 21 | #endif |
| 22 | |
| 23 | #ifdef clearerr |
| 24 | #error clearerr is defined |
| 25 | #endif |
| 26 | |
| 27 | #ifdef feof |
| 28 | #error feof is defined |
| 29 | #endif |
| 30 | |
| 31 | #ifdef ferror |
| 32 | #error ferror is defined |
| 33 | #endif |
| 34 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 35 | #ifndef BUFSIZ |
| 36 | #error BUFSIZ not defined |
| 37 | #endif |
| 38 | |
| 39 | #ifndef EOF |
| 40 | #error EOF not defined |
| 41 | #endif |
| 42 | |
| 43 | #ifndef FILENAME_MAX |
| 44 | #error FILENAME_MAX not defined |
| 45 | #endif |
| 46 | |
| 47 | #ifndef FOPEN_MAX |
| 48 | #error FOPEN_MAX not defined |
| 49 | #endif |
| 50 | |
| 51 | #ifndef L_tmpnam |
| 52 | #error L_tmpnam not defined |
| 53 | #endif |
| 54 | |
| 55 | #ifndef NULL |
| 56 | #error NULL not defined |
| 57 | #endif |
| 58 | |
| 59 | #ifndef SEEK_CUR |
| 60 | #error SEEK_CUR not defined |
| 61 | #endif |
| 62 | |
| 63 | #ifndef SEEK_END |
| 64 | #error SEEK_END not defined |
| 65 | #endif |
| 66 | |
| 67 | #ifndef SEEK_SET |
| 68 | #error SEEK_SET not defined |
| 69 | #endif |
| 70 | |
| 71 | #ifndef TMP_MAX |
| 72 | #error TMP_MAX not defined |
| 73 | #endif |
| 74 | |
| 75 | #ifndef _IOFBF |
| 76 | #error _IOFBF not defined |
| 77 | #endif |
| 78 | |
| 79 | #ifndef _IOLBF |
| 80 | #error _IOLBF not defined |
| 81 | #endif |
| 82 | |
| 83 | #ifndef _IONBF |
| 84 | #error _IONBF not defined |
| 85 | #endif |
| 86 | |
| 87 | #ifndef stderr |
| 88 | #error stderr not defined |
| 89 | #endif |
| 90 | |
| 91 | #ifndef stdin |
| 92 | #error stdin not defined |
| 93 | #endif |
| 94 | |
| 95 | #ifndef stdout |
| 96 | #error stdout not defined |
| 97 | #endif |
| 98 | |
| 99 | #include <cstdarg> |
| 100 | |
Saleem Abdulrasool | c409aa8 | 2017-02-18 19:28:41 +0000 | [diff] [blame] | 101 | #if defined(__GNUC__) || defined(__clang__) |
Eric Fiselier | 203f687 | 2015-07-18 22:51:51 +0000 | [diff] [blame] | 102 | #pragma GCC diagnostic ignored "-Wformat-zero-length" |
| 103 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" // for tmpnam |
Eric Fiselier | e5eb704 | 2016-04-28 01:49:03 +0000 | [diff] [blame] | 104 | #endif |
Howard Hinnant | 167d0fb | 2012-02-25 20:04:11 +0000 | [diff] [blame] | 105 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 106 | int main() |
| 107 | { |
| 108 | FILE* fp = 0; |
Mehdi Amini | dff33c2 | 2017-03-03 17:24:29 +0000 | [diff] [blame] | 109 | fpos_t fpos = fpos_t(); |
Eric Fiselier | fb42f4c | 2016-05-02 19:15:48 +0000 | [diff] [blame] | 110 | size_t s = 0; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 111 | char* cp = 0; |
Eric Fiselier | 203f687 | 2015-07-18 22:51:51 +0000 | [diff] [blame] | 112 | char arr[] = {'a', 'b'}; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 113 | va_list va; |
Eric Fiselier | fb42f4c | 2016-05-02 19:15:48 +0000 | [diff] [blame] | 114 | ((void)fp); // Prevent unused warning |
| 115 | ((void)fpos); // Prevent unused warning |
| 116 | ((void)s); // Prevent unused warning |
| 117 | ((void)cp); // Prevent unused warning |
| 118 | ((void)arr); // Prevent unused warning |
| 119 | ((void)va); // Prevent unused warning |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 120 | static_assert((std::is_same<decltype(remove("")), int>::value), ""); |
| 121 | static_assert((std::is_same<decltype(rename("","")), int>::value), ""); |
| 122 | static_assert((std::is_same<decltype(tmpfile()), FILE*>::value), ""); |
| 123 | static_assert((std::is_same<decltype(tmpnam(cp)), char*>::value), ""); |
| 124 | static_assert((std::is_same<decltype(fclose(fp)), int>::value), ""); |
| 125 | static_assert((std::is_same<decltype(fflush(fp)), int>::value), ""); |
| 126 | static_assert((std::is_same<decltype(fopen("", "")), FILE*>::value), ""); |
| 127 | static_assert((std::is_same<decltype(freopen("", "", fp)), FILE*>::value), ""); |
| 128 | static_assert((std::is_same<decltype(setbuf(fp,cp)), void>::value), ""); |
| 129 | static_assert((std::is_same<decltype(vfprintf(fp,"",va)), int>::value), ""); |
Howard Hinnant | fb7f07e | 2011-05-13 21:52:40 +0000 | [diff] [blame] | 130 | static_assert((std::is_same<decltype(fprintf(fp," ")), int>::value), ""); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 131 | static_assert((std::is_same<decltype(fscanf(fp,"")), int>::value), ""); |
Howard Hinnant | fb7f07e | 2011-05-13 21:52:40 +0000 | [diff] [blame] | 132 | static_assert((std::is_same<decltype(printf("\n")), int>::value), ""); |
| 133 | static_assert((std::is_same<decltype(scanf("\n")), int>::value), ""); |
| 134 | static_assert((std::is_same<decltype(snprintf(cp,0,"p")), int>::value), ""); |
| 135 | static_assert((std::is_same<decltype(sprintf(cp," ")), int>::value), ""); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 136 | static_assert((std::is_same<decltype(sscanf("","")), int>::value), ""); |
| 137 | static_assert((std::is_same<decltype(vfprintf(fp,"",va)), int>::value), ""); |
| 138 | static_assert((std::is_same<decltype(vfscanf(fp,"",va)), int>::value), ""); |
Howard Hinnant | fb7f07e | 2011-05-13 21:52:40 +0000 | [diff] [blame] | 139 | static_assert((std::is_same<decltype(vprintf(" ",va)), int>::value), ""); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 140 | static_assert((std::is_same<decltype(vscanf("",va)), int>::value), ""); |
Howard Hinnant | fb7f07e | 2011-05-13 21:52:40 +0000 | [diff] [blame] | 141 | static_assert((std::is_same<decltype(vsnprintf(cp,0," ",va)), int>::value), ""); |
| 142 | static_assert((std::is_same<decltype(vsprintf(cp," ",va)), int>::value), ""); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 143 | static_assert((std::is_same<decltype(vsscanf("","",va)), int>::value), ""); |
| 144 | static_assert((std::is_same<decltype(fgetc(fp)), int>::value), ""); |
| 145 | static_assert((std::is_same<decltype(fgets(cp,0,fp)), char*>::value), ""); |
| 146 | static_assert((std::is_same<decltype(fputc(0,fp)), int>::value), ""); |
| 147 | static_assert((std::is_same<decltype(fputs("",fp)), int>::value), ""); |
| 148 | static_assert((std::is_same<decltype(getc(fp)), int>::value), ""); |
| 149 | static_assert((std::is_same<decltype(getchar()), int>::value), ""); |
Eric Fiselier | 203f687 | 2015-07-18 22:51:51 +0000 | [diff] [blame] | 150 | #if TEST_STD_VER < 14 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 151 | static_assert((std::is_same<decltype(gets(cp)), char*>::value), ""); |
Eric Fiselier | 399e99a | 2014-08-10 22:39:11 +0000 | [diff] [blame] | 152 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 153 | static_assert((std::is_same<decltype(putc(0,fp)), int>::value), ""); |
| 154 | static_assert((std::is_same<decltype(putchar(0)), int>::value), ""); |
| 155 | static_assert((std::is_same<decltype(puts("")), int>::value), ""); |
| 156 | static_assert((std::is_same<decltype(ungetc(0,fp)), int>::value), ""); |
| 157 | static_assert((std::is_same<decltype(fread((void*)0,0,0,fp)), size_t>::value), ""); |
Eric Fiselier | 203f687 | 2015-07-18 22:51:51 +0000 | [diff] [blame] | 158 | static_assert((std::is_same<decltype(fwrite((const void*)arr,1,0,fp)), size_t>::value), ""); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 159 | static_assert((std::is_same<decltype(fgetpos(fp, &fpos)), int>::value), ""); |
| 160 | static_assert((std::is_same<decltype(fseek(fp, 0,0)), int>::value), ""); |
| 161 | static_assert((std::is_same<decltype(fsetpos(fp, &fpos)), int>::value), ""); |
| 162 | static_assert((std::is_same<decltype(ftell(fp)), long>::value), ""); |
| 163 | static_assert((std::is_same<decltype(rewind(fp)), void>::value), ""); |
| 164 | static_assert((std::is_same<decltype(clearerr(fp)), void>::value), ""); |
| 165 | static_assert((std::is_same<decltype(feof(fp)), int>::value), ""); |
| 166 | static_assert((std::is_same<decltype(ferror(fp)), int>::value), ""); |
| 167 | static_assert((std::is_same<decltype(perror("")), void>::value), ""); |
| 168 | } |