default.pass.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. // <utility>
  9. // template <class T1, class T2> struct pair
  10. // explicit(see-below) constexpr pair();
  11. // NOTE: The SFINAE on the default constructor is tested in
  12. // default-sfinae.pass.cpp
  13. #include <utility>
  14. #include <type_traits>
  15. #include <cassert>
  16. #include "test_macros.h"
  17. #include "archetypes.h"
  18. int main(int, char**)
  19. {
  20. {
  21. typedef std::pair<float, short*> P;
  22. P p;
  23. assert(p.first == 0.0f);
  24. assert(p.second == nullptr);
  25. }
  26. #if TEST_STD_VER >= 11
  27. {
  28. typedef std::pair<float, short*> P;
  29. constexpr P p;
  30. static_assert(p.first == 0.0f, "");
  31. static_assert(p.second == nullptr, "");
  32. }
  33. {
  34. using NoDefault = ImplicitTypes::NoDefault;
  35. using P = std::pair<int, NoDefault>;
  36. static_assert(!std::is_default_constructible<P>::value, "");
  37. using P2 = std::pair<NoDefault, int>;
  38. static_assert(!std::is_default_constructible<P2>::value, "");
  39. }
  40. {
  41. struct Base { };
  42. struct Derived : Base { protected: Derived() = default; };
  43. static_assert(!std::is_default_constructible<std::pair<Derived, int> >::value, "");
  44. }
  45. #endif
  46. return 0;
  47. }