47 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: no-random-device10 11// <random>12 13// class random_device;14 15// result_type operator()();16 17#include <random>18#include <cassert>19#include <string>20#include <system_error>21 22#include "test_macros.h"23 24int main(int, char**)25{26 {27 std::random_device r;28 std::random_device::result_type e = r();29 ((void)e); // Prevent unused warning30 }31 32 // When using the `/dev/urandom` implementation, make sure that we throw33 // an exception when we hit EOF while reading the custom-provided file.34#if !defined(TEST_HAS_NO_EXCEPTIONS) && defined(_LIBCPP_USING_DEV_RANDOM)35 {36 std::random_device r("/dev/null");37 try {38 (void)r();39 LIBCPP_ASSERT(false);40 } catch (const std::system_error&) {41 }42 }43#endif44 45 return 0;46}47