This repository was archived by the owner on Nov 1, 2021. It is now read-only.
File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -1723,7 +1723,8 @@ static bool ShouldDiagnoseUnusedDecl(const NamedDecl *D) {
1723
1723
dyn_cast<CXXConstructExpr>(Init);
1724
1724
if (Construct && !Construct->isElidable()) {
1725
1725
CXXConstructorDecl *CD = Construct->getConstructor();
1726
- if (!CD->isTrivial() && !RD->hasAttr<WarnUnusedAttr>())
1726
+ if (!CD->isTrivial() && !RD->hasAttr<WarnUnusedAttr>() &&
1727
+ !VD->evaluateValue())
1727
1728
return false;
1728
1729
}
1729
1730
}
Original file line number Diff line number Diff line change 1
1
// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++1y-extensions -verify %s
2
+ // RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++1y-extensions -verify -std=c++11 %s
2
3
template <typename T> void f () {
3
4
T t;
4
5
t = 17 ;
@@ -194,3 +195,35 @@ void test() {
194
195
}
195
196
196
197
}
198
+
199
+ #if __cplusplus >= 201103L
200
+ namespace with_constexpr {
201
+ template <typename T>
202
+ struct Literal {
203
+ T i;
204
+ Literal () = default ;
205
+ constexpr Literal (T i) : i(i) {}
206
+ };
207
+
208
+ struct NoLiteral {
209
+ int i;
210
+ NoLiteral () = default ;
211
+ constexpr NoLiteral (int i) : i(i) {}
212
+ ~NoLiteral () {}
213
+ };
214
+
215
+ static Literal<int > gl1; // expected-warning {{unused variable 'gl1'}}
216
+ static Literal<int > gl2 (1 ); // expected-warning {{unused variable 'gl2'}}
217
+ static const Literal<int > gl3 (0 ); // expected-warning {{unused variable 'gl3'}}
218
+
219
+ template <typename T>
220
+ void test (int i) {
221
+ Literal<int > l1; // expected-warning {{unused variable 'l1'}}
222
+ Literal<int > l2 (42 ); // expected-warning {{unused variable 'l2'}}
223
+ Literal<int > l3 (i); // no-warning
224
+ Literal<T> l4 (0 ); // no-warning
225
+ NoLiteral nl1; // no-warning
226
+ NoLiteral nl2 (42 ); // no-warning
227
+ }
228
+ }
229
+ #endif
You can’t perform that action at this time.
0 commit comments