| 1 |
// { dg-options "-fno-inline" } |
| 2 |
// { dg-do run { target c++26 } } |
| 3 |
// { dg-additional-files "filebuf_members-1.txt" } |
| 4 |
|
| 5 |
#include <fstream> |
| 6 |
|
| 7 |
using type = std::basic_filebuf<wchar_t>::native_handle_type; |
| 8 |
|
| 9 |
#include <cstdio> // std::fclose(FILE*) |
| 10 |
#if __has_include(<unistd.h>) |
| 11 |
# include <unistd.h> // close(int) |
| 12 |
#endif |
| 13 |
#if __has_include(<io.h>) |
| 14 |
# include <io.h> // _open_osfhandle |
| 15 |
# include <fcntl.h> // _O_RDONLY, _O_TEXT |
| 16 |
#endif |
| 17 |
|
| 18 |
#include <testsuite_hooks.h> |
| 19 |
|
| 20 |
void |
| 21 |
test01() |
| 22 |
{ |
| 23 |
std::wfilebuf f; |
| 24 |
f.open("filebuf_members-1.txt", std::wios::in); |
| 25 |
type handle = f.native_handle(); |
| 26 |
|
| 27 |
auto native_close = []<typename HandleT>(HandleT handle) { |
| 28 |
if constexpr (std::is_same_v<HandleT, std::FILE*>) |
| 29 |
std::fclose(handle); // --enable-cstdio=stdio_pure |
| 30 |
#if __has_include(<unistd.h>) |
| 31 |
else if constexpr (std::is_same_v<HandleT, int>) |
| 32 |
::close(handle); // POSIX |
| 33 |
#endif |
| 34 |
#if __has_include(<handleapi.h>) |
| 35 |
else if constexpr (std::is_same_v<HandleT, void*>) // Windows |
| 36 |
::_close(::_open_osfhandle((intptr_t)handle, _O_RDONLY|_O_TEXT)); |
| 37 |
#endif |
| 38 |
else |
| 39 |
VERIFY( false ); |
| 40 |
}; |
| 41 |
native_close(handle); |
| 42 |
|
| 43 |
try |
| 44 |
{ |
| 45 |
f.sgetc(); |
| 46 |
VERIFY( false ); |
| 47 |
} |
| 48 |
catch (const std::ios::failure&) |
| 49 |
{ |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
int main() |
| 54 |
{ |
| 55 |
test01(); |
| 56 |
} |