|
1 | | -// RUN: %clang_cc1 -fsyntax-only -Wunused-private-field -Wused-but-marked-unused -Wno-uninitialized -verify -std=c++11 %s |
2 | | -// RUN: %clang_cc1 -fsyntax-only -Wunused-private-field -Wused-but-marked-unused -Wno-uninitialized -verify -std=c++17 %s |
3 | | -// RUN: %clang_cc1 -fsyntax-only -Wunused-private-field -Wused-but-marked-unused -Wno-uninitialized -verify -std=c++20 %s |
| 1 | +// RUN: %clang_cc1 -fsyntax-only -Wunused -Wused-but-marked-unused -Wno-uninitialized -verify -std=c++11 %s |
| 2 | +// RUN: %clang_cc1 -fsyntax-only -Wunused -Wused-but-marked-unused -Wno-uninitialized -verify -std=c++17 %s |
| 3 | +// RUN: %clang_cc1 -fsyntax-only -Wunused -Wused-but-marked-unused -Wno-uninitialized -verify -std=c++20 %s |
4 | 4 |
|
5 | 5 | #if __cplusplus >= 202002L |
6 | 6 |
|
@@ -108,7 +108,7 @@ class ClassWithTemplateFriend { |
108 | 108 | template <typename T> class TemplateFriend { |
109 | 109 | public: |
110 | 110 | TemplateFriend(ClassWithTemplateFriend my_friend) { |
111 | | - int var = my_friend.used_by_friend_; |
| 111 | + int var = my_friend.used_by_friend_; // expected-warning {{unused variable 'var'}} |
112 | 112 | } |
113 | 113 | }; |
114 | 114 |
|
@@ -181,10 +181,10 @@ class EverythingUsed { |
181 | 181 | public: |
182 | 182 | EverythingUsed() : as_array_index_(0), var_(by_initializer_) { |
183 | 183 | var_ = sizeof(sizeof_); |
184 | | - int *use = &by_reference_; |
| 184 | + int *use = &by_reference_; // expected-warning {{unused variable 'use'}} |
185 | 185 | int test[2]; |
186 | 186 | test[as_array_index_] = 42; |
187 | | - int EverythingUsed::*ptr = &EverythingUsed::by_pointer_to_member_; |
| 187 | + int EverythingUsed::*ptr = &EverythingUsed::by_pointer_to_member_; // expected-warning {{unused variable 'ptr'}} |
188 | 188 | } |
189 | 189 |
|
190 | 190 | template<class T> |
@@ -336,9 +336,21 @@ class [[gnu::warn_unused]] S { |
336 | 336 | S(); |
337 | 337 | }; |
338 | 338 |
|
| 339 | +struct [[maybe_unused]] T {}; |
| 340 | + |
| 341 | +void f() { |
| 342 | + int i = 0; // expected-warning {{unused variable 'i'}} |
| 343 | + S s; // expected-warning {{unused variable 's'}} |
| 344 | + T t; // ok |
| 345 | +} |
| 346 | + |
339 | 347 | class C { |
340 | 348 | private: |
341 | 349 | const int i = 0; // expected-warning {{private field 'i' is not used}} |
342 | | - const S s; // expected-warning {{private field 's' is not used}} |
| 350 | + int j = 0; // expected-warning {{private field 'j' is not used}} |
| 351 | + const S s1; // expected-warning {{private field 's1' is not used}} |
| 352 | + const T t1; // ok |
| 353 | + S s2; // expected-warning {{private field 's2' is not used}} |
| 354 | + T t2; // ok |
343 | 355 | }; |
344 | 356 | } |
0 commit comments