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 // template <class Alloc>
12 // struct allocator_traits
13 // {
14 //     static constexpr pointer allocate(allocator_type& a, size_type n);
15 //     ...
16 // };
17 
18 // UNSUPPORTED: c++03, c++11, c++14, c++17
19 
20 #include <memory>
21 #include <cstdint>
22 #include <cassert>
23 
24 #include "test_macros.h"
25 
26 template <class T>
27 struct A
28 {
29     typedef T value_type;
30 
allocateA31     value_type* allocate(std::size_t n)
32     {
33         assert(n == 12);
34         return reinterpret_cast<value_type*>(static_cast<std::uintptr_t>(0xEEADBEEF));
35     }
allocateA36     value_type* allocate(std::size_t n, const void* p)
37     {
38         assert(n == 11);
39         assert(p == 0);
40         return reinterpret_cast<value_type*>(static_cast<std::uintptr_t>(0xFEADBEEF));
41     }
42 };
43 
main(int,char **)44 int main(int, char**)
45 {
46     A<int> a;
47     std::allocator_traits<A<int> >::allocate(a, 10);          // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
48     std::allocator_traits<A<int> >::allocate(a, 10, nullptr); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
49 
50     return 0;
51 }
52