Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // test <stdio.h> |
| 11 | |
| 12 | #include <stdio.h> |
| 13 | #include <type_traits> |
Eric Fiselier | 212714f | 2015-07-18 22:51:51 +0000 | [diff] [blame] | 14 | #include "test_macros.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 15 | |
| 16 | #ifndef BUFSIZ |
| 17 | #error BUFSIZ not defined |
| 18 | #endif |
| 19 | |
| 20 | #ifndef EOF |
| 21 | #error EOF not defined |
| 22 | #endif |
| 23 | |
| 24 | #ifndef FILENAME_MAX |
| 25 | #error FILENAME_MAX not defined |
| 26 | #endif |
| 27 | |
| 28 | #ifndef FOPEN_MAX |
| 29 | #error FOPEN_MAX not defined |
| 30 | #endif |
| 31 | |
| 32 | #ifndef L_tmpnam |
| 33 | #error L_tmpnam not defined |
| 34 | #endif |
| 35 | |
| 36 | #ifndef NULL |
| 37 | #error NULL not defined |
| 38 | #endif |
| 39 | |
| 40 | #ifndef SEEK_CUR |
| 41 | #error SEEK_CUR not defined |
| 42 | #endif |
| 43 | |
| 44 | #ifndef SEEK_END |
| 45 | #error SEEK_END not defined |
| 46 | #endif |
| 47 | |
| 48 | #ifndef SEEK_SET |
| 49 | #error SEEK_SET not defined |
| 50 | #endif |
| 51 | |
| 52 | #ifndef TMP_MAX |
| 53 | #error TMP_MAX not defined |
| 54 | #endif |
| 55 | |
| 56 | #ifndef _IOFBF |
| 57 | #error _IOFBF not defined |
| 58 | #endif |
| 59 | |
| 60 | #ifndef _IOLBF |
| 61 | #error _IOLBF not defined |
| 62 | #endif |
| 63 | |
| 64 | #ifndef _IONBF |
| 65 | #error _IONBF not defined |
| 66 | #endif |
| 67 | |
| 68 | #ifndef stderr |
| 69 | #error stderr not defined |
| 70 | #endif |
| 71 | |
| 72 | #ifndef stdin |
| 73 | #error stdin not defined |
| 74 | #endif |
| 75 | |
| 76 | #ifndef stdout |
| 77 | #error stdout not defined |
| 78 | #endif |
| 79 | |
| 80 | #include <cstdarg> |
| 81 | |
Eric Fiselier | 212714f | 2015-07-18 22:51:51 +0000 | [diff] [blame] | 82 | #pragma GCC diagnostic ignored "-Wformat-zero-length" |
| 83 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" // for tmpnam |
Howard Hinnant | 896baa2 | 2012-02-25 20:04:11 +0000 | [diff] [blame] | 84 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 85 | int main() |
| 86 | { |
| 87 | FILE* fp = 0; |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 88 | fpos_t fpos = {0}; |
| 89 | size_t s = 0; ((void)s); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 90 | char* cp = 0; |
Eric Fiselier | 212714f | 2015-07-18 22:51:51 +0000 | [diff] [blame] | 91 | char arr[] = {'a', 'b'}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 92 | va_list va; |
| 93 | static_assert((std::is_same<decltype(remove("")), int>::value), ""); |
| 94 | static_assert((std::is_same<decltype(rename("","")), int>::value), ""); |
| 95 | static_assert((std::is_same<decltype(tmpfile()), FILE*>::value), ""); |
| 96 | static_assert((std::is_same<decltype(tmpnam(cp)), char*>::value), ""); |
| 97 | static_assert((std::is_same<decltype(fclose(fp)), int>::value), ""); |
| 98 | static_assert((std::is_same<decltype(fflush(fp)), int>::value), ""); |
| 99 | static_assert((std::is_same<decltype(fopen("", "")), FILE*>::value), ""); |
| 100 | static_assert((std::is_same<decltype(freopen("", "", fp)), FILE*>::value), ""); |
| 101 | static_assert((std::is_same<decltype(setbuf(fp,cp)), void>::value), ""); |
| 102 | static_assert((std::is_same<decltype(vfprintf(fp,"",va)), int>::value), ""); |
Howard Hinnant | 0a11111 | 2011-05-13 21:52:40 +0000 | [diff] [blame] | 103 | static_assert((std::is_same<decltype(fprintf(fp," ")), int>::value), ""); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 104 | static_assert((std::is_same<decltype(fscanf(fp,"")), int>::value), ""); |
Howard Hinnant | 0a11111 | 2011-05-13 21:52:40 +0000 | [diff] [blame] | 105 | static_assert((std::is_same<decltype(printf("\n")), int>::value), ""); |
| 106 | static_assert((std::is_same<decltype(scanf("\n")), int>::value), ""); |
| 107 | static_assert((std::is_same<decltype(snprintf(cp,0,"p")), int>::value), ""); |
| 108 | static_assert((std::is_same<decltype(sprintf(cp," ")), int>::value), ""); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 109 | static_assert((std::is_same<decltype(sscanf("","")), int>::value), ""); |
| 110 | static_assert((std::is_same<decltype(vfprintf(fp,"",va)), int>::value), ""); |
| 111 | static_assert((std::is_same<decltype(vfscanf(fp,"",va)), int>::value), ""); |
Howard Hinnant | 0a11111 | 2011-05-13 21:52:40 +0000 | [diff] [blame] | 112 | static_assert((std::is_same<decltype(vprintf(" ",va)), int>::value), ""); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 113 | static_assert((std::is_same<decltype(vscanf("",va)), int>::value), ""); |
Howard Hinnant | 0a11111 | 2011-05-13 21:52:40 +0000 | [diff] [blame] | 114 | static_assert((std::is_same<decltype(vsnprintf(cp,0," ",va)), int>::value), ""); |
| 115 | static_assert((std::is_same<decltype(vsprintf(cp," ",va)), int>::value), ""); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 116 | static_assert((std::is_same<decltype(vsscanf("","",va)), int>::value), ""); |
| 117 | static_assert((std::is_same<decltype(fgetc(fp)), int>::value), ""); |
| 118 | static_assert((std::is_same<decltype(fgets(cp,0,fp)), char*>::value), ""); |
| 119 | static_assert((std::is_same<decltype(fputc(0,fp)), int>::value), ""); |
| 120 | static_assert((std::is_same<decltype(fputs("",fp)), int>::value), ""); |
| 121 | static_assert((std::is_same<decltype(getc(fp)), int>::value), ""); |
| 122 | static_assert((std::is_same<decltype(getchar()), int>::value), ""); |
Eric Fiselier | 212714f | 2015-07-18 22:51:51 +0000 | [diff] [blame] | 123 | #if TEST_STD_VER < 14 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 124 | static_assert((std::is_same<decltype(gets(cp)), char*>::value), ""); |
Eric Fiselier | e48b0c4 | 2014-08-10 22:39:11 +0000 | [diff] [blame] | 125 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 126 | static_assert((std::is_same<decltype(putc(0,fp)), int>::value), ""); |
| 127 | static_assert((std::is_same<decltype(putchar(0)), int>::value), ""); |
| 128 | static_assert((std::is_same<decltype(puts("")), int>::value), ""); |
| 129 | static_assert((std::is_same<decltype(ungetc(0,fp)), int>::value), ""); |
| 130 | static_assert((std::is_same<decltype(fread((void*)0,0,0,fp)), size_t>::value), ""); |
Eric Fiselier | 212714f | 2015-07-18 22:51:51 +0000 | [diff] [blame] | 131 | static_assert((std::is_same<decltype(fwrite((const void*)arr,1,0,fp)), size_t>::value), ""); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 132 | static_assert((std::is_same<decltype(fgetpos(fp, &fpos)), int>::value), ""); |
| 133 | static_assert((std::is_same<decltype(fseek(fp, 0,0)), int>::value), ""); |
| 134 | static_assert((std::is_same<decltype(fsetpos(fp, &fpos)), int>::value), ""); |
| 135 | static_assert((std::is_same<decltype(ftell(fp)), long>::value), ""); |
| 136 | static_assert((std::is_same<decltype(rewind(fp)), void>::value), ""); |
| 137 | static_assert((std::is_same<decltype(clearerr(fp)), void>::value), ""); |
| 138 | static_assert((std::is_same<decltype(feof(fp)), int>::value), ""); |
| 139 | static_assert((std::is_same<decltype(ferror(fp)), int>::value), ""); |
| 140 | static_assert((std::is_same<decltype(perror("")), void>::value), ""); |
| 141 | } |