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 // UNSUPPORTED: libcpp-has-no-threads
10
11 // <atomic>
12
13 // template <class T>
14 // T* atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op)
15 // template <class T>
16 // T* atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op);
17
18 #include <atomic>
19
void_pointer()20 void void_pointer() {
21 {
22 volatile std::atomic<void*> obj;
23 // expected-error@atomic:* {{incomplete type 'void' where a complete type is required}}
24 std::atomic_fetch_add(&obj, 0);
25 }
26 {
27 std::atomic<void*> obj;
28 // expected-error@atomic:* {{incomplete type 'void' where a complete type is required}}
29 std::atomic_fetch_add(&obj, 0);
30 }
31 }
32
33 struct Incomplete;
34
pointer_to_incomplete_type()35 void pointer_to_incomplete_type() {
36 {
37 volatile std::atomic<Incomplete*> obj;
38 // expected-error@atomic:* {{incomplete type 'Incomplete' where a complete type is required}}
39 std::atomic_fetch_add(&obj, 0);
40 }
41 {
42 std::atomic<Incomplete*> obj;
43 // expected-error@atomic:* {{incomplete type 'Incomplete' where a complete type is required}}
44 std::atomic_fetch_add(&obj, 0);
45 }
46 }
47
function_pointer()48 void function_pointer() {
49 {
50 volatile std::atomic<void (*)(int)> fun;
51 // expected-error@atomic:* {{static_assert failed due to requirement '!is_function<void (int)>::value' "Pointer to function isn't allowed"}}
52 std::atomic_fetch_add(&fun, 0);
53 }
54 {
55 std::atomic<void (*)(int)> fun;
56 // expected-error@atomic:* {{static_assert failed due to requirement '!is_function<void (int)>::value' "Pointer to function isn't allowed"}}
57 std::atomic_fetch_add(&fun, 0);
58 }
59 }
60
61 struct S {
62 void fun(int);
63 };
64
member_function_pointer()65 void member_function_pointer() {
66 {
67 volatile std::atomic<void (S::*)(int)> fun;
68 // expected-error@atomic:* {{no member named 'fetch_add' in}}
69 std::atomic_fetch_add(&fun, 0);
70 }
71 {
72 std::atomic<void (S::*)(int)> fun;
73 // expected-error@atomic:* {{no member named 'fetch_add' in}}
74 std::atomic_fetch_add(&fun, 0);
75 }
76 }
77