if (D->isInvalidDecl() || D->isUsed() || D->hasAttr<UnusedAttr>())
return false;
- // Ignore class templates.
+ // Ignore all entities declared within templates, and out-of-line definitions
+ // of members of class templates.
if (D->getDeclContext()->isDependentContext() ||
D->getLexicalDeclContext()->isDependentContext())
return false;
if (DC->getRedeclContext()->isFileContext() && VD->isExternallyVisible())
AddPushedVisibilityAttribute(VD);
- if (VD->isFileVarDecl())
+ // FIXME: Warn on unused templates.
+ if (VD->isFileVarDecl() && !VD->getDescribedVarTemplate())
MarkUnusedFileScopedDecl(VD);
// Now we have parsed the initializer and can update the table of magic
--- /dev/null
+// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -verify %s
+
+static int unused_local_static;
+
+namespace PR8455 {
+ void f() {
+ A: // expected-warning {{unused label 'A'}}
+ __attribute__((unused)) int i; // attribute applies to variable
+ B: // attribute applies to label
+ __attribute__((unused)); int j; // expected-warning {{unused variable 'j'}}
+ }
+
+ void g() {
+ C: // unused label 'C' will not appear here because an error has occurred
+ __attribute__((unused))
+ #pragma weak unused_local_static // expected-error {{expected ';' after __attribute__}}
+ ;
+ }
+
+ void h() {
+ D: // expected-warning {{unused label 'D'}}
+ #pragma weak unused_local_static
+ __attribute__((unused)) // expected-warning {{declaration does not declare anything}}
+ ;
+ }
+}
-// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++1y-extensions -verify %s
template<typename T> void f() {
T t;
t = 17;
}
}
+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>;
+
+ // FIXME: It'd be nice to warn here.
+ template<typename T> int m = 0;
+}
+
namespace ctor_with_cleanups {
struct S1 {
~S1();
}
#include "Inputs/warn-unused-variables.h"
-
-namespace PR8455 {
- void f() {
- A: // expected-warning {{unused label 'A'}}
- __attribute__((unused)) int i; // attribute applies to variable
- B: // attribute applies to label
- __attribute__((unused)); int j; // expected-warning {{unused variable 'j'}}
- }
-
- void g() {
- C: // unused label 'C' will not appear here because an error occurs
- __attribute__((unused))
- #pragma weak unused_local_static // expected-error {{expected ';' after __attribute__}}
- ;
- }
-
- void h() {
- D: // expected-warning {{unused label 'D'}}
- #pragma weak unused_local_static
- __attribute__((unused)) // expected-warning {{declaration does not declare anything}}
- ;
- }
-}