| 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 | |
| 34 | class CppAttribute : public QObject |
| 35 | { |
| 36 | Q_OBJECT |
| 37 | signals: |
| 38 | [[deprecated]] void deprecatedSignal(); |
| 39 | |
| 40 | public slots: |
| 41 | [[deprecated]] void deprecatedSlot() {} |
| 42 | [[deprecated]] [[tst_moc::maybe_unused]] int deprecatedSlot2() { return 42; } |
| 43 | [[deprecated("reason" )]] void deprecatedReason() {} |
| 44 | [[deprecated("reason[" )]] void deprecatedReasonWithLBRACK() {} |
| 45 | [[deprecated("reason[[" )]] void deprecatedReasonWith2LBRACK() {} |
| 46 | [[deprecated("reason]" )]] void deprecatedReasonWithRBRACK() {} |
| 47 | [[deprecated("reason]]" )]] void deprecatedReasonWith2RBRACK() {} |
| 48 | void slotWithArguments([[tst_moc::maybe_unused]] int) {} |
| 49 | #if !defined(_MSC_VER) || _MSC_VER >= 1912 |
| 50 | // On MSVC it causes: |
| 51 | // moc_cxx-attributes.cpp(133): fatal error C1001: An internal error has occurred in the compiler. |
| 52 | Q_INVOKABLE [[tst_moc::noreturn]] void noreturnSlot() { throw "unused" ; } |
| 53 | [[tst_moc::noreturn]] Q_SCRIPTABLE void noreturnSlot2() { throw "unused" ; } |
| 54 | [[deprecated]] int returnInt() { return 0; } |
| 55 | Q_SLOT [[tst_moc::noreturn]] [[deprecated]] void noreturnDeprecatedSlot() { throw "unused" ; } |
| 56 | Q_INVOKABLE void noreturnSlot3() [[tst_moc::noreturn]] { throw "unused" ; } |
| 57 | #endif |
| 58 | }; |
| 59 | |
| 60 | #ifdef Q_MOC_RUN |
| 61 | # define TEST_COMPILER_DEPRECATION [[deprecated]] |
| 62 | # define TEST_COMPILER_DEPRECATION_X(x) [[deprecated(x)]] |
| 63 | #else |
| 64 | # define TEST_COMPILER_DEPRECATION Q_DECL_ENUMERATOR_DEPRECATED |
| 65 | # define TEST_COMPILER_DEPRECATION_X(x) Q_DECL_ENUMERATOR_DEPRECATED_X(x) |
| 66 | #endif |
| 67 | |
| 68 | namespace TestQNamespaceDeprecated { |
| 69 | Q_NAMESPACE |
| 70 | enum class TestEnum1 { |
| 71 | Key1 = 11, |
| 72 | Key2 TEST_COMPILER_DEPRECATION, |
| 73 | Key3 TEST_COMPILER_DEPRECATION_X("reason" ), |
| 74 | Key4 TEST_COMPILER_DEPRECATION_X("reason[" ), |
| 75 | Key5 TEST_COMPILER_DEPRECATION_X("reason[[" ), |
| 76 | Key6 TEST_COMPILER_DEPRECATION_X("reason]" ), |
| 77 | Key7 TEST_COMPILER_DEPRECATION_X("reason]]" ), |
| 78 | }; |
| 79 | Q_ENUM_NS(TestEnum1) |
| 80 | |
| 81 | // try to dizzy moc by adding a struct in between |
| 82 | struct TestGadget { |
| 83 | Q_GADGET |
| 84 | public: |
| 85 | enum class TestGEnum1 { |
| 86 | Key1 = 13, |
| 87 | Key2 TEST_COMPILER_DEPRECATION, |
| 88 | Key3 TEST_COMPILER_DEPRECATION_X("reason" ) |
| 89 | }; |
| 90 | Q_ENUM(TestGEnum1) |
| 91 | }; |
| 92 | |
| 93 | enum class TestFlag1 { |
| 94 | None = 0, |
| 95 | Flag1 = 1, |
| 96 | Flag2 TEST_COMPILER_DEPRECATION = 2, |
| 97 | Flag3 TEST_COMPILER_DEPRECATION_X("reason" ) = 3, |
| 98 | Any = Flag1 | Flag2 | Flag3 |
| 99 | }; |
| 100 | Q_FLAG_NS(TestFlag1) |
| 101 | } |
| 102 | |
| 103 | #endif // CXXATTRIBUTE_H |
| 104 | |