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. // constexpr pair();
  11. // This test doesn't pass due to a constexpr bug in GCC 4.9 that fails
  12. // to initialize any type without a user provided constructor in a constant
  13. // expression (e.g. float).
  14. // XFAIL: gcc-4.9
  15. // NOTE: The SFINAE on the default constructor is tested in
  16. // default-sfinae.pass.cpp
  17. #include <utility>
  18. #include <type_traits>
  19. #include <cassert>
  20. #include "test_macros.h"
  21. #include "archetypes.h"
  22. int main(int, char**)
  23. {
  24. {
  25. typedef std::pair<float, short*> P;
  26. P p;
  27. assert(p.first == 0.0f);
  28. assert(p.second == nullptr);
  29. }
  30. #if TEST_STD_VER >= 11
  31. {
  32. typedef std::pair<float, short*> P;
  33. constexpr P p;
  34. static_assert(p.first == 0.0f, "");
  35. static_assert(p.second == nullptr, "");
  36. }
  37. {
  38. using NoDefault = ImplicitTypes::NoDefault;
  39. using P = std::pair<int, NoDefault>;
  40. static_assert(!std::is_default_constructible<P>::value, "");
  41. using P2 = std::pair<NoDefault, int>;
  42. static_assert(!std::is_default_constructible<P2>::value, "");
  43. }
  44. #endif
  45. return 0;
  46. }