Skip to content

Commit ff26d33

Browse files
committed
add additional test cases
1 parent 55fb96c commit ff26d33

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

clang/test/SemaCXX/warn-unused-private-field.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
44

55
#if __cplusplus >= 202002L
66

@@ -108,7 +108,7 @@ class ClassWithTemplateFriend {
108108
template <typename T> class TemplateFriend {
109109
public:
110110
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'}}
112112
}
113113
};
114114

@@ -181,10 +181,10 @@ class EverythingUsed {
181181
public:
182182
EverythingUsed() : as_array_index_(0), var_(by_initializer_) {
183183
var_ = sizeof(sizeof_);
184-
int *use = &by_reference_;
184+
int *use = &by_reference_; // expected-warning {{unused variable 'use'}}
185185
int test[2];
186186
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'}}
188188
}
189189

190190
template<class T>
@@ -336,9 +336,21 @@ class [[gnu::warn_unused]] S {
336336
S();
337337
};
338338

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+
339347
class C {
340348
private:
341349
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
343355
};
344356
}

0 commit comments

Comments
 (0)