get.fail.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. // <array>
  9. // template <size_t I, class T, size_t N> T& get(array<T, N>& a);
  10. // Prevent -Warray-bounds from issuing a diagnostic when testing with clang verify.
  11. #if defined(__clang__)
  12. #pragma clang diagnostic ignored "-Warray-bounds"
  13. #endif
  14. #include <array>
  15. #include <cassert>
  16. // std::array is explicitly allowed to be initialized with A a = { init-list };.
  17. // Disable the missing braces warning for this reason.
  18. #include "disable_missing_braces_warning.h"
  19. int main(int, char**)
  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. // expected-error-re@array:* {{static_assert failed{{( due to requirement '3U[L]{0,2} < 3U[L]{0,2}')?}} "Index out of bounds in std::get<> (std::array)"}}
  27. }
  28. return 0;
  29. }