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 
9 // <memory>
10 
11 // allocator:
12 // constexpr T* allocate(size_type n);
13 
14 // UNSUPPORTED: c++03, c++11, c++14, c++17
15 
16 #include <memory>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 
21 template <typename T>
test()22 constexpr bool test()
23 {
24     typedef std::allocator<T> A;
25     typedef std::allocator_traits<A> AT;
26     A a;
27     TEST_IGNORE_NODISCARD a.allocate(AT::max_size(a) + 1);           // just barely too large
28     TEST_IGNORE_NODISCARD a.allocate(AT::max_size(a) * 2);           // significantly too large
29     TEST_IGNORE_NODISCARD a.allocate(((size_t) -1) / sizeof(T) + 1); // multiply will overflow
30     TEST_IGNORE_NODISCARD a.allocate((size_t) -1);                   // way too large
31 
32     return true;
33 }
34 
main(int,char **)35 int main(int, char**)
36 {
37     static_assert(test<double>()); // expected-error {{static_assert expression is not an integral constant expression}}
38     LIBCPP_STATIC_ASSERT(test<const double>()); // expected-error {{static_assert expression is not an integral constant expression}}
39     return 0;
40 }
41