QtBase  v6.3.1
cxx-attributes.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2019 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28 
29 #ifndef CXXATTRIBUTE_H
30 #define CXXATTRIBUTE_H
31 
32 #include <QtCore/QObject>
33 
35 QT_WARNING_DISABLE_CLANG("-Wunknown-attributes")
36 QT_WARNING_DISABLE_GCC("-Wattributes")
37 
38 class CppAttribute : public QObject
39 {
40  Q_OBJECT
41 signals:
42  [[deprecated]] void deprecatedSignal();
43 
44 public slots:
45  [[deprecated]] void deprecatedSlot() {}
46  [[deprecated]] [[tst_moc::maybe_unused]] int deprecatedSlot2() { return 42; }
47  [[deprecated("reason")]] void deprecatedReason() {}
48  [[deprecated("reason[")]] void deprecatedReasonWithLBRACK() {}
49  [[deprecated("reason[[")]] void deprecatedReasonWith2LBRACK() {}
50  [[deprecated("reason]")]] void deprecatedReasonWithRBRACK() {}
51  [[deprecated("reason]]")]] void deprecatedReasonWith2RBRACK() {}
52  void slotWithArguments([[tst_moc::maybe_unused]] int) {}
53 #if !defined(_MSC_VER) || _MSC_VER >= 1912
54  // On MSVC it causes:
55  // moc_cxx-attributes.cpp(133): fatal error C1001: An internal error has occurred in the compiler.
56  Q_INVOKABLE [[tst_moc::noreturn]] void noreturnSlot() { throw "unused"; }
57  [[tst_moc::noreturn]] Q_SCRIPTABLE void noreturnSlot2() { throw "unused"; }
58  [[deprecated]] int returnInt() { return 0; }
59  Q_SLOT [[tst_moc::noreturn]] [[deprecated]] void noreturnDeprecatedSlot() { throw "unused"; }
60  Q_INVOKABLE void noreturnSlot3() [[tst_moc::noreturn]] { throw "unused"; }
61 #endif
62 };
63 
65 
66 #ifdef Q_MOC_RUN
67 # define TEST_COMPILER_DEPRECATION [[deprecated]]
68 # define TEST_COMPILER_DEPRECATION_X(x) [[deprecated(x)]]
69 #else
70 # define TEST_COMPILER_DEPRECATION Q_DECL_ENUMERATOR_DEPRECATED
71 # define TEST_COMPILER_DEPRECATION_X(x) Q_DECL_ENUMERATOR_DEPRECATED_X(x)
72 #endif
73 
76 
79  enum class TestEnum1 {
80  Key1 = 11,
82  Key3 TEST_COMPILER_DEPRECATION_X("reason"),
83  Key4 TEST_COMPILER_DEPRECATION_X("reason["),
84  Key5 TEST_COMPILER_DEPRECATION_X("reason[["),
85  Key6 TEST_COMPILER_DEPRECATION_X("reason]"),
86  Key7 TEST_COMPILER_DEPRECATION_X("reason]]"),
87  };
89 
90  // try to dizzy moc by adding a struct in between
91  struct TestGadget {
92  Q_GADGET
93  public:
94  enum class TestGEnum1 {
95  Key1 = 13,
97  Key3 TEST_COMPILER_DEPRECATION_X("reason")
98  };
99  Q_ENUM(TestGEnum1)
100  };
101 
102  enum class TestFlag1 {
103  None = 0,
104  Flag1 = 1,
106  Flag3 TEST_COMPILER_DEPRECATION_X("reason") = 3,
107  Any = Flag1 | Flag2 | Flag3
108  };
110 }
111 
113 
114 #endif // CXXATTRIBUTE_H
void deprecatedReason()
void deprecatedReasonWithLBRACK()
void deprecatedSlot()
int deprecatedSlot2()
void deprecatedSignal()
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
#define TEST_COMPILER_DEPRECATION_X(x)
#define TEST_COMPILER_DEPRECATION
#define QT_WARNING_POP
#define QT_WARNING_DISABLE_DEPRECATED
#define QT_WARNING_DISABLE_GCC(text)
#define QT_WARNING_PUSH
#define QT_WARNING_DISABLE_CLANG(text)
#define Q_ENUM(x)
Definition: qtmetamacros.h:104
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define Q_SCRIPTABLE
Definition: qtmetamacros.h:111
#define Q_INVOKABLE
Definition: qtmetamacros.h:112
#define Q_FLAG_NS(x)
Definition: qtmetamacros.h:110
#define Q_GADGET
Definition: qtmetamacros.h:193
#define Q_ENUM_NS(x)
Definition: qtmetamacros.h:109
#define slots
Definition: qtmetamacros.h:76
#define signals
Definition: qtmetamacros.h:77
#define Q_SLOT
Definition: qtmetamacros.h:114
#define Q_NAMESPACE
Definition: qtmetamacros.h:202
@ Flag2
Definition: tst_qdebug.cpp:728