Skip to content

Commit 93638b7

Browse files
committedOct 14, 2017
Revert rL315787, "[Sema] Warn about unused variables if we can constant evaluate the initializer."
check-libcxx dislikes it. llvm-svn: 315806
1 parent 98f0c43 commit 93638b7

File tree

2 files changed

+1
-35
lines changed

2 files changed

+1
-35
lines changed
 

‎clang/lib/Sema/SemaDecl.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1723,8 +1723,7 @@ static bool ShouldDiagnoseUnusedDecl(const NamedDecl *D) {
17231723
dyn_cast<CXXConstructExpr>(Init);
17241724
if (Construct && !Construct->isElidable()) {
17251725
CXXConstructorDecl *CD = Construct->getConstructor();
1726-
if (!CD->isTrivial() && !RD->hasAttr<WarnUnusedAttr>() &&
1727-
!VD->evaluateValue())
1726+
if (!CD->isTrivial() && !RD->hasAttr<WarnUnusedAttr>())
17281727
return false;
17291728
}
17301729
}

‎clang/test/SemaCXX/warn-unused-variables.cpp

-33
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// 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
32
template<typename T> void f() {
43
T t;
54
t = 17;
@@ -195,35 +194,3 @@ void test() {
195194
}
196195

197196
}
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

0 commit comments

Comments
 (0)