1 // RUN: %clang_cc1 -fsyntax-only -verify -Wunused %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 -Wunused %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wunused %s
4 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 -Wunused %s
6 // PR4103 : Make sure we don't get a bogus unused expression warning
9 char foo
; // expected-warning {{private field 'foo' is not used}}
11 class APSInt
: public APInt
{
12 char bar
; // expected-warning {{private field 'bar' is not used}}
14 APSInt
&operator=(const APSInt
&RHS
);
17 APSInt
& APSInt::operator=(const APSInt
&RHS
) {
18 APInt::operator=(RHS
);
32 namespace derefvolatile
{
33 void f(volatile char* x
) {
35 #if __cplusplus <= 199711L
36 // expected-warning@-2 {{expression result unused; assign into a variable to force a volatile load}}
39 #if __cplusplus <= 199711L
40 // expected-warning@-2 {{expression result unused; assign into a variable to force a volatile load}}
43 (void)y
; // don't warn here, because it's a common pattern.
47 namespace AnonObject
{
49 Foo(const char* const message
);
53 Foo("Hello World!"); // don't warn
54 int(1); // expected-warning {{expression result unused}}
58 // Test that constructing an object (which may have side effects) with
59 // constructor arguments which are dependent doesn't produce an unused value
61 namespace UnresolvedLookup
{
68 Foo(t
, 0); // no warning
73 #if __cplusplus >= 201703L
76 struct X
{ int a
, b
; } x
;
77 auto [a
, b
] = x
; // expected-warning {{unused variable '[a, b]'}}
82 template<typename T
> void f() {
83 struct A
{ int n
; } a
[1];
87 auto [y
] = a
[0]; // expected-warning {{unused}}
89 template<bool b
> void g() {
90 struct A
{ int n
; } a
[1];
98 (void)y
; // ok, even when b == false
100 template<typename T
> void h() {
101 struct A
{ int n
; } a
[1];
102 for (auto [x
] : a
) { // expected-warning {{unused variable '[x]'}}
106 f
<int>(); // expected-note {{instantiation of}}
109 h
<int>(); // expected-note {{instantiation of}}
113 namespace maybe_unused_binding
{
116 struct X
{ int a
, b
; } x
;
117 auto [a
[[maybe_unused
]], b
] = x
; // expected-warning {{an attribute specifier sequence attached to a structured binding declaration is a C++2c extension}}