brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 8940f1c Raw
52 lines · cpp
1// -*- C++ -*-2//===----------------------------------------------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10// UNSUPPORTED: c++03, c++11, c++1411// REQUIRES: c++experimental12 13// <experimental/memory>14 15// observer_ptr16//17// constexpr observer_ptr(nullptr_t) noexcept;18 19#include <experimental/memory>20#include <cassert>21#include <cstddef>22#include <type_traits>23 24template <class T>25constexpr void test_nullptr_ctor() {26  using Ptr = std::experimental::observer_ptr<T>;27  Ptr ptr   = nullptr;28  assert(ptr.get() == nullptr);29  static_assert(std::is_nothrow_constructible<Ptr, std::nullptr_t>::value);30}31 32struct Foo;33struct Bar {34  Bar(int) {}35};36 37constexpr bool test() {38  test_nullptr_ctor<Foo>();39  test_nullptr_ctor<Bar>();40  test_nullptr_ctor<int>();41  test_nullptr_ctor<void>();42 43  return true;44}45 46int main(int, char**) {47  test();48  static_assert(test());49 50  return 0;51}52