| 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 |
|
| 100 |
TEST_CLANG_DIAGNOSTIC_IGNORED("-Wformat-zero-length") |
| 101 |
TEST_GCC_DIAGNOSTIC_IGNORED("-Wformat-zero-length") |
| 102 |
|
| 103 |
FILE* fp = 0; |
| 104 |
fpos_t fpos = fpos_t(); |
| 105 |
size_t s = 0; |
| 106 |
char* cp = 0; |
| 107 |
char arr[] = {'a', 'b'}; |
| 108 |
va_list va; |
| 109 |
ASSERT_SAME_TYPE(int, decltype(remove(""))); |
| 110 |
ASSERT_SAME_TYPE(int, decltype(rename("",""))); |
| 111 |
ASSERT_SAME_TYPE(FILE*, decltype(tmpfile())); |
| 112 |
TEST_DIAGNOSTIC_PUSH |
| 113 |
TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations") |
| 114 |
TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations") |
| 115 |
ASSERT_SAME_TYPE(char*, decltype(tmpnam(cp))); |
| 116 |
TEST_DIAGNOSTIC_POP |
| 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"))); |
| 128 |
TEST_DIAGNOSTIC_PUSH |
| 129 |
TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations") |
| 130 |
TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations") |
| 131 |
ASSERT_SAME_TYPE(int, decltype(sprintf(cp," "))); |
| 132 |
TEST_DIAGNOSTIC_POP |
| 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))); |
| 139 |
TEST_DIAGNOSTIC_PUSH |
| 140 |
TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations") |
| 141 |
TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations") |
| 142 |
ASSERT_SAME_TYPE(int, decltype(vsprintf(cp," ",va))); |
| 143 |
TEST_DIAGNOSTIC_POP |
| 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 |
| 152 |
TEST_DIAGNOSTIC_PUSH |
| 153 |
TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations") |
| 154 |
TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations") |
| 155 |
ASSERT_SAME_TYPE(char*, decltype(gets(cp))); |
| 156 |
TEST_DIAGNOSTIC_POP |
| 157 |
#endif |
| 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(""))); |