2014-04-03 02:28:36 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++1y-extensions -verify %s
|
2009-10-09 05:35:42 +08:00
|
|
|
template<typename T> void f() {
|
2010-02-12 06:55:30 +08:00
|
|
|
T t;
|
|
|
|
t = 17;
|
2009-10-09 05:35:42 +08:00
|
|
|
}
|
2009-11-07 15:26:56 +08:00
|
|
|
|
2009-11-07 16:24:59 +08:00
|
|
|
// PR5407
|
2009-11-07 15:26:56 +08:00
|
|
|
struct A { A(); };
|
|
|
|
struct B { ~B(); };
|
|
|
|
void f() {
|
|
|
|
A a;
|
|
|
|
B b;
|
2009-11-07 16:24:59 +08:00
|
|
|
}
|
2009-11-18 01:11:23 +08:00
|
|
|
|
|
|
|
// PR5531
|
|
|
|
namespace PR5531 {
|
|
|
|
struct A {
|
|
|
|
};
|
|
|
|
|
|
|
|
struct B {
|
|
|
|
B(int);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct C {
|
|
|
|
~C();
|
|
|
|
};
|
|
|
|
|
|
|
|
void test() {
|
2010-07-08 14:14:04 +08:00
|
|
|
A();
|
2009-11-18 01:11:23 +08:00
|
|
|
B(17);
|
|
|
|
C();
|
|
|
|
}
|
|
|
|
}
|
2009-12-24 08:28:18 +08:00
|
|
|
|
2010-02-12 06:55:30 +08:00
|
|
|
template<typename T>
|
|
|
|
struct X0 { };
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void test_dependent_init(T *p) {
|
|
|
|
X0<int> i(p);
|
|
|
|
(void)i;
|
|
|
|
}
|
2010-04-28 00:20:13 +08:00
|
|
|
|
2010-11-09 22:57:47 +08:00
|
|
|
void unused_local_static() {
|
|
|
|
static int x = 0;
|
|
|
|
static int y = 0; // expected-warning{{unused variable 'y'}}
|
|
|
|
#pragma unused(x)
|
|
|
|
}
|
2011-06-22 07:42:09 +08:00
|
|
|
|
|
|
|
// PR10168
|
|
|
|
namespace PR10168 {
|
|
|
|
// We expect a warning in the definition only for non-dependent variables, and
|
|
|
|
// a warning in the instantiation only for dependent variables.
|
|
|
|
template<typename T>
|
|
|
|
struct S {
|
|
|
|
void f() {
|
|
|
|
int a; // expected-warning {{unused variable 'a'}}
|
|
|
|
T b; // expected-warning 2{{unused variable 'b'}}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void f() {
|
|
|
|
int a; // expected-warning {{unused variable 'a'}}
|
|
|
|
T b; // expected-warning 2{{unused variable 'b'}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void g() {
|
|
|
|
S<int>().f(); // expected-note {{here}}
|
|
|
|
S<char>().f(); // expected-note {{here}}
|
|
|
|
f<int>(); // expected-note {{here}}
|
|
|
|
f<char>(); // expected-note {{here}}
|
|
|
|
}
|
|
|
|
}
|
2012-01-06 12:54:01 +08:00
|
|
|
|
|
|
|
namespace PR11550 {
|
|
|
|
struct S1 {
|
|
|
|
S1();
|
|
|
|
};
|
|
|
|
S1 makeS1();
|
|
|
|
void testS1(S1 a) {
|
|
|
|
// This constructor call can be elided.
|
|
|
|
S1 x = makeS1(); // expected-warning {{unused variable 'x'}}
|
|
|
|
|
|
|
|
// This one cannot, so no warning.
|
|
|
|
S1 y;
|
|
|
|
|
|
|
|
// This call cannot, but the constructor is trivial.
|
|
|
|
S1 z = a; // expected-warning {{unused variable 'z'}}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The same is true even when we know thet constructor has side effects.
|
|
|
|
void foo();
|
|
|
|
struct S2 {
|
|
|
|
S2() {
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
S2 makeS2();
|
|
|
|
void testS2(S2 a) {
|
|
|
|
S2 x = makeS2(); // expected-warning {{unused variable 'x'}}
|
|
|
|
S2 y;
|
|
|
|
S2 z = a; // expected-warning {{unused variable 'z'}}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Or when the constructor is not declared by the user.
|
|
|
|
struct S3 {
|
|
|
|
S1 m;
|
|
|
|
};
|
|
|
|
S3 makeS3();
|
|
|
|
void testS3(S3 a) {
|
|
|
|
S3 x = makeS3(); // expected-warning {{unused variable 'x'}}
|
|
|
|
S3 y;
|
|
|
|
S3 z = a; // expected-warning {{unused variable 'z'}}
|
|
|
|
}
|
|
|
|
}
|
2012-10-25 05:29:06 +08:00
|
|
|
|
2014-04-03 02:28:36 +08:00
|
|
|
namespace PR19305 {
|
|
|
|
template<typename T> int n = 0; // no warning
|
|
|
|
int a = n<int>;
|
|
|
|
|
|
|
|
template<typename T> const int l = 0; // no warning
|
|
|
|
int b = l<int>;
|
|
|
|
|
2014-04-26 03:21:40 +08:00
|
|
|
// PR19558
|
|
|
|
template<typename T> const int o = 0; // no warning
|
|
|
|
template<typename T> const int o<T*> = 0; // no warning
|
|
|
|
int c = o<int*>;
|
|
|
|
|
|
|
|
template<> int o<void> = 0; // no warning
|
|
|
|
int d = o<void>;
|
|
|
|
|
2014-04-03 02:28:36 +08:00
|
|
|
// FIXME: It'd be nice to warn here.
|
|
|
|
template<typename T> int m = 0;
|
2014-04-26 03:21:40 +08:00
|
|
|
template<typename T> int m<T*> = 0;
|
|
|
|
|
|
|
|
template<> const int m<void> = 0; // expected-warning {{unused variable}}
|
2014-04-03 02:28:36 +08:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:29:06 +08:00
|
|
|
namespace ctor_with_cleanups {
|
|
|
|
struct S1 {
|
|
|
|
~S1();
|
|
|
|
};
|
|
|
|
struct S2 {
|
|
|
|
S2(const S1&);
|
|
|
|
};
|
|
|
|
void func() {
|
|
|
|
S2 s((S1()));
|
|
|
|
}
|
|
|
|
}
|
2013-04-10 08:47:10 +08:00
|
|
|
|
|
|
|
#include "Inputs/warn-unused-variables.h"
|
2016-10-27 21:30:51 +08:00
|
|
|
|
|
|
|
namespace arrayRecords {
|
|
|
|
|
2016-11-03 00:11:30 +08:00
|
|
|
class NonTriviallyDestructible {
|
2016-10-27 21:30:51 +08:00
|
|
|
public:
|
2016-11-03 00:11:30 +08:00
|
|
|
~NonTriviallyDestructible() {}
|
2016-10-27 21:30:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Foo {
|
|
|
|
int x;
|
|
|
|
Foo(int x) : x(x) {}
|
|
|
|
};
|
|
|
|
|
2016-11-03 00:11:30 +08:00
|
|
|
struct Elidable {
|
|
|
|
Elidable();
|
2016-10-27 21:30:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void foo(int size) {
|
2016-11-03 00:11:30 +08:00
|
|
|
Elidable elidable; // no warning
|
|
|
|
Elidable elidableArray[2]; // no warning
|
|
|
|
Elidable elidableDynArray[size]; // no warning
|
|
|
|
Elidable elidableNestedArray[1][2][3]; // no warning
|
2016-10-27 21:30:51 +08:00
|
|
|
|
2016-11-03 00:11:30 +08:00
|
|
|
NonTriviallyDestructible scalar; // no warning
|
|
|
|
NonTriviallyDestructible array[2]; // no warning
|
|
|
|
NonTriviallyDestructible nestedArray[2][2]; // no warning
|
2016-10-27 21:30:51 +08:00
|
|
|
|
|
|
|
Foo fooScalar = 1; // expected-warning {{unused variable 'fooScalar'}}
|
|
|
|
Foo fooArray[] = {1,2}; // expected-warning {{unused variable 'fooArray'}}
|
|
|
|
Foo fooNested[2][2] = { {1,2}, {3,4} }; // expected-warning {{unused variable 'fooNested'}}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<int N>
|
|
|
|
void bar() {
|
2016-11-03 00:11:30 +08:00
|
|
|
NonTriviallyDestructible scaler; // no warning
|
|
|
|
NonTriviallyDestructible array[N]; // no warning
|
2016-10-27 21:30:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test() {
|
|
|
|
foo(10);
|
|
|
|
bar<2>();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|