Add FreeBSD/aarch64 architecture.
[deliverable/binutils-gdb.git] / gdb / common / poison.h
1 /* Poison symbols at compile time.
2
3 Copyright (C) 2017 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #ifndef COMMON_POISON_H
21 #define COMMON_POISON_H
22
23 #include "traits.h"
24
25 /* Poison memset of non-POD types. The idea is catching invalid
26 initialization of non-POD structs that is easy to be introduced as
27 side effect of refactoring. For example, say this:
28
29 struct S { VEC(foo_s) *m_data; };
30
31 is converted to this at some point:
32
33 struct S {
34 S() { m_data.reserve (10); }
35 std::vector<foo> m_data;
36 };
37
38 and old code was initializing S objects like this:
39
40 struct S s;
41 memset (&s, 0, sizeof (S)); // whoops, now wipes vector.
42
43 Declaring memset as deleted for non-POD types makes the memset above
44 be a compile-time error. */
45
46 /* Helper for SFINAE. True if "T *" is memsettable. I.e., if T is
47 either void, or POD. */
48 template<typename T>
49 struct IsMemsettable
50 : gdb::Or<std::is_void<T>,
51 std::is_pod<T>>
52 {};
53
54 template <typename T,
55 typename = gdb::Requires<gdb::Not<IsMemsettable<T>>>>
56 void *memset (T *s, int c, size_t n) = delete;
57
58 #if HAVE_IS_TRIVIALLY_COPYABLE
59
60 /* Similarly, poison memcpy and memmove of non trivially-copyable
61 types, which is undefined. */
62
63 /* True if "T *" is relocatable. I.e., copyable with memcpy/memmove.
64 I.e., T is either trivially copyable, or void. */
65 template<typename T>
66 struct IsRelocatable
67 : gdb::Or<std::is_void<T>,
68 std::is_trivially_copyable<T>>
69 {};
70
71 /* True if both source and destination are relocatable. */
72
73 template <typename D, typename S>
74 using BothAreRelocatable
75 = gdb::And<IsRelocatable<D>, IsRelocatable<S>>;
76
77 template <typename D, typename S,
78 typename = gdb::Requires<gdb::Not<BothAreRelocatable<D, S>>>>
79 void *memcpy (D *dest, const S *src, size_t n) = delete;
80
81 template <typename D, typename S,
82 typename = gdb::Requires<gdb::Not<BothAreRelocatable<D, S>>>>
83 void *memmove (D *dest, const S *src, size_t n) = delete;
84
85 #endif /* HAVE_IS_TRIVIALLY_COPYABLE */
86
87 #endif /* COMMON_POISON_H */
This page took 0.031139 seconds and 4 git commands to generate.