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