PR19305: Don't issue -Wunused-variable warnings on variable templates. It's not

meaningful to odr-use the VarDecl inside a variable template. (Separately, it'd
be nice to track referenced-ness for templates, and warn on unused ones, but
that's really a distinct issue...)

Move a test that generates and tests a warning-suppressing error out to its own
test file, so it doesn't have weird effects on the other tests in the same file.

llvm-svn: 205448
This commit is contained in:
Richard Smith 2014-04-02 18:28:36 +00:00
parent 65813a3bce
commit c392617cff
3 changed files with 42 additions and 26 deletions

View File

@ -1204,7 +1204,8 @@ bool Sema::ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const {
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;
@ -9044,7 +9045,8 @@ Sema::FinalizeDeclaration(Decl *ThisDecl) {
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

View File

@ -0,0 +1,26 @@
// 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}}
;
}
}

View File

@ -1,4 +1,4 @@
// 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;
@ -115,6 +115,17 @@ namespace PR11550 {
}
}
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();
@ -128,26 +139,3 @@ namespace ctor_with_cleanups {
}
#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}}
;
}
}