make_shared.volatile.pass.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. // <memory>
  9. // shared_ptr
  10. // template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args);
  11. #include <memory>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. template <typename T>
  15. void test(const T &t0)
  16. {
  17. {
  18. T t1 = t0;
  19. std::shared_ptr<T> p0 = std::make_shared<T>(t0);
  20. std::shared_ptr<T> p1 = std::make_shared<T>(t1);
  21. assert(*p0 == t0);
  22. assert(*p1 == t1);
  23. }
  24. {
  25. const T t1 = t0;
  26. std::shared_ptr<const T> p0 = std::make_shared<const T>(t0);
  27. std::shared_ptr<const T> p1 = std::make_shared<const T>(t1);
  28. assert(*p0 == t0);
  29. assert(*p1 == t1);
  30. }
  31. {
  32. volatile T t1 = t0;
  33. std::shared_ptr<volatile T> p0 = std::make_shared<volatile T>(t0);
  34. std::shared_ptr<volatile T> p1 = std::make_shared<volatile T>(t1);
  35. assert(*p0 == t0);
  36. assert(*p1 == t1);
  37. }
  38. {
  39. const volatile T t1 = t0;
  40. std::shared_ptr<const volatile T> p0 = std::make_shared<const volatile T>(t0);
  41. std::shared_ptr<const volatile T> p1 = std::make_shared<const volatile T>(t1);
  42. assert(*p0 == t0);
  43. assert(*p1 == t1);
  44. }
  45. }
  46. int main(int, char**)
  47. {
  48. test<bool>(true);
  49. test<int>(3);
  50. test<double>(5.0);
  51. return 0;
  52. }