@@ -86,16 +86,18 @@ class TestUnusedFunctions : public TestFixture {
8686 TEST_CASE (parensInit);
8787 TEST_CASE (typeInCast);
8888 TEST_CASE (attributeCleanup);
89+ TEST_CASE (attributeUnused);
90+ TEST_CASE (attributeMaybeUnused);
8991 }
9092
9193#define check (...) check_(__FILE__, __LINE__, __VA_ARGS__)
9294 template <size_t size>
93- void check_ (const char * file, int line, const char (&code)[size], Platform::Type platform = Platform::Type::Native, const Settings *s = nullptr) {
95+ void check_ (const char * file, int line, const char (&code)[size], Platform::Type platform = Platform::Type::Native, const Settings *s = nullptr, bool cpp = true ) {
9496 const Settings settings1 = settingsBuilder (s ? *s : settings).platform (platform).build ();
9597
9698 // Tokenize..
9799 SimpleTokenizer tokenizer (settings1, *this );
98- ASSERT_LOC (tokenizer.tokenize (code), file, line);
100+ ASSERT_LOC (tokenizer.tokenize (code, cpp ), file, line);
99101
100102 // Check for unused functions..
101103 CheckUnusedFunctions checkUnusedFunctions;
@@ -794,6 +796,30 @@ class TestUnusedFunctions : public TestFixture {
794796 " }\n " );
795797 ASSERT_EQUALS (" " , errout_str ());
796798 }
799+
800+ void attributeUnused ()
801+ {
802+ check (" [[unused]] void f() {}\n " );
803+ ASSERT_EQUALS (" " , errout_str ());
804+
805+ check (" [[gnu::unused]] void f() {}\n " );
806+ ASSERT_EQUALS (" " , errout_str ());
807+
808+ check (" __attribute__((unused)) void f() {}\n " );
809+ ASSERT_EQUALS (" " , errout_str ());
810+ }
811+
812+ void attributeMaybeUnused ()
813+ {
814+ check (" [[__maybe_unused__]] void f() {}\n " , Platform::Type::Native, nullptr , false );
815+ ASSERT_EQUALS (" " , errout_str ());
816+
817+ check (" [[maybe_unused]] void f() {}\n " , Platform::Type::Native, nullptr , false );
818+ ASSERT_EQUALS (" " , errout_str ());
819+
820+ check (" [[maybe_unused]] void f() {}\n " );
821+ ASSERT_EQUALS (" " , errout_str ());
822+ }
797823};
798824
799825REGISTER_TEST (TestUnusedFunctions)
0 commit comments