1 // Copyright (C) 2017-2020 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library.  This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3.  If not see
16 // <http://www.gnu.org/licenses/>.
17 
18 // { dg-options "-std=gnu++17" }
19 // { dg-do compile { target c++17 } }
20 // { dg-require-atomic-builtins "" }
21 
22 #include <atomic>
23 
24 void
test01()25 test01()
26 {
27   std::atomic<void*> p;
28   p.fetch_add(1); // { dg-error "from here" }
29   p.fetch_sub(1); // { dg-error "from here" }
30   p += 1;	  // { dg-error "from here" }
31   p -= 1;	  // { dg-error "from here" }
32   ++p;		  // { dg-error "from here" }
33   p++;		  // { dg-error "from here" }
34   --p;		  // { dg-error "from here" }
35   p--;		  // { dg-error "from here" }
36 }
37 
38 void
test02()39 test02()
40 {
41   std::atomic<void(*)()> p;
42   p.fetch_add(1); // { dg-error "from here" }
43   p.fetch_sub(1); // { dg-error "from here" }
44   p += 1;	  // { dg-error "from here" }
45   p -= 1;	  // { dg-error "from here" }
46   ++p;		  // { dg-error "from here" }
47   p++;		  // { dg-error "from here" }
48   --p;		  // { dg-error "from here" }
49   p--;		  // { dg-error "from here" }
50 }
51 
52 void
test03()53 test03()
54 {
55   volatile std::atomic<void*> p;
56   p.fetch_add(1); // { dg-error "from here" }
57   p.fetch_sub(1); // { dg-error "from here" }
58   p += 1;	  // { dg-error "from here" }
59   p -= 1;	  // { dg-error "from here" }
60   ++p;		  // { dg-error "from here" }
61   p++;		  // { dg-error "from here" }
62   --p;		  // { dg-error "from here" }
63   p--;		  // { dg-error "from here" }
64 }
65 
66 void
test04()67 test04()
68 {
69   volatile std::atomic<void(*)()> p;
70   p.fetch_add(1); // { dg-error "from here" }
71   p.fetch_sub(1); // { dg-error "from here" }
72   p += 1;	  // { dg-error "from here" }
73   p -= 1;	  // { dg-error "from here" }
74   ++p;		  // { dg-error "from here" }
75   p++;		  // { dg-error "from here" }
76   --p;		  // { dg-error "from here" }
77   p--;		  // { dg-error "from here" }
78 }
79 
80 // { dg-prune-output "static assertion failed" }
81