warn-access: wrong -Wdangling-pointer with labels [PR106080]
[official-gcc.git] / gcc / tristate.h
blob38293f5a26c58bb84842871e33032104acaab6fd
1 /* "True" vs "False" vs "Unknown".
2 Copyright (C) 2019-2023 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef GCC_TRISTATE_H
22 #define GCC_TRISTATE_H
24 /* "True" vs "False" vs "Unknown". */
26 class tristate {
27 public:
28 enum value {
29 TS_UNKNOWN,
30 TS_TRUE,
31 TS_FALSE
34 tristate (enum value val) : m_value (val) {}
35 tristate (bool val) : m_value (val ? TS_TRUE : TS_FALSE) {}
36 static tristate unknown () { return tristate (TS_UNKNOWN); }
38 const char *as_string () const;
40 bool is_known () const { return m_value != TS_UNKNOWN; }
41 bool is_unknown () const { return m_value == TS_UNKNOWN; }
42 bool is_true () const { return m_value == TS_TRUE; }
43 bool is_false () const { return m_value == TS_FALSE; }
45 tristate not_ () const;
46 tristate or_ (tristate other) const;
47 tristate and_ (tristate other) const;
49 bool operator== (const tristate &other) const
51 return m_value == other.m_value;
54 bool operator!= (const tristate &other) const
56 return m_value != other.m_value;
59 enum value get_value () const { return m_value; }
61 private:
62 enum value m_value;
65 /* Overloaded boolean operators on tristates. */
67 inline tristate
68 operator ! (tristate t)
70 return t.not_ ();
73 inline tristate
74 operator || (tristate a, tristate b)
76 return a.or_ (b);
79 inline tristate
80 operator && (tristate a, tristate b)
82 return a.and_ (b);
85 #endif /* GCC_TRISTATE_H */