get.fail.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <array>
  10. // template <size_t I, class T, size_t N> T& get(array<T, N>& a);
  11. // Prevent -Warray-bounds from issuing a diagnostic when testing with clang verify.
  12. #if defined(__clang__)
  13. #pragma clang diagnostic ignored "-Warray-bounds"
  14. #endif
  15. #include <array>
  16. #include <cassert>
  17. #include "test_macros.h"
  18. #include "../suppress_array_warnings.h"
  19. int main()
  20. {
  21. {
  22. typedef double T;
  23. typedef std::array<T, 3> C;
  24. C c = {1, 2, 3.5};
  25. std::get<3>(c) = 5.5; // expected-note {{requested here}}
  26. #if TEST_STD_VER >= 11
  27. // expected-error@array:* {{static_assert failed "Index out of bounds in std::get<> (std::array)"}}
  28. #else
  29. // expected-error@array:* {{implicit instantiation of undefined template '__static_assert_test<false>'}}
  30. #endif
  31. }
  32. }