brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 22cc63e Raw
59 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++2310 11// <fstream>12 13// class basic_filebuf;14 15// native_handle_type native_handle() const noexcept;16 17#include <cassert>18#include <fstream>19#include <filesystem>20#include <utility>21 22#include "platform_support.h"23#include "test_macros.h"24#include "../native_handle_test_helpers.h"25 26template <typename CharT>27void test() {28  std::basic_filebuf<CharT> f;29  std::filesystem::path p = get_temp_file_name();30 31  // non-const32  {33    assert(f.open(p, std::ios_base::in) != nullptr);34    std::same_as<NativeHandleT> decltype(auto) handle = f.native_handle();35    assert(is_handle_valid(handle));36    f.close();37    assert(!is_handle_valid(handle));38    static_assert(noexcept(f.native_handle()));39  }40  // const41  {42    assert(f.open(p, std::ios_base::in) != nullptr);43    std::same_as<NativeHandleT> decltype(auto) const_handle = std::as_const(f).native_handle();44    assert(is_handle_valid(const_handle));45    f.close();46    assert(!is_handle_valid(const_handle));47    static_assert(noexcept(std::as_const(f).native_handle()));48  }49}50 51int main(int, char**) {52  test<char>();53#ifndef TEST_HAS_NO_WIDE_CHARACTERS54  test<wchar_t>();55#endif56 57  return 0;58}59