default.explicit.fail.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. // UNSUPPORTED: c++98, c++03
  9. // Before GCC 6, aggregate initialization kicks in.
  10. // See https://stackoverflow.com/q/41799015/627587.
  11. // UNSUPPORTED: gcc-5
  12. // <utility>
  13. // template <class T1, class T2> struct pair
  14. // explicit(see-below) constexpr pair();
  15. // This test checks the conditional explicitness of std::pair's default
  16. // constructor as introduced by the resolution of LWG 2510.
  17. #include <utility>
  18. struct ImplicitlyDefaultConstructible {
  19. ImplicitlyDefaultConstructible() = default;
  20. };
  21. struct ExplicitlyDefaultConstructible {
  22. explicit ExplicitlyDefaultConstructible() = default;
  23. };
  24. std::pair<ImplicitlyDefaultConstructible, ExplicitlyDefaultConstructible> test1() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}}
  25. std::pair<ExplicitlyDefaultConstructible, ImplicitlyDefaultConstructible> test2() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}}
  26. std::pair<ExplicitlyDefaultConstructible, ExplicitlyDefaultConstructible> test3() { return {}; } // expected-error 1 {{chosen constructor is explicit in copy-initialization}}
  27. std::pair<ImplicitlyDefaultConstructible, ImplicitlyDefaultConstructible> test4() { return {}; }
  28. int main(int, char**) {
  29. return 0;
  30. }