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 <cstddef>
17#include <memory>
18
19#include "test_macros.h"
20
21template <typename T>
22constexpr 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(((std::size_t) -1) / sizeof(T) + 1); // multiply will overflow
30 TEST_IGNORE_NODISCARD a.allocate((std::size_t) -1); // way too large
31
32 return true;
33}
34
35void f() {
36 static_assert(test<double>()); // expected-error {{static assertion expression is not an integral constant expression}}
37 LIBCPP_STATIC_ASSERT(test<const double>()); // expected-error {{static assertion expression is not an integral constant expression}}
38}
39

source code of libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.constexpr.size.verify.cpp