Enabling the subject list for the warn_unused attribute, and adding a test case. Previously, would issue a "warning ignored" diagnostic instead of the more specific "only applies to."

llvm-svn: 195851
This commit is contained in:
Aaron Ballman 2013-11-27 16:59:17 +00:00
parent 4a611153e1
commit 6a42b5a0c5
3 changed files with 16 additions and 24 deletions

View File

@ -846,7 +846,7 @@ def VecReturn : InheritableAttr {
def WarnUnused : InheritableAttr {
let Spellings = [GNU<"warn_unused">];
// let Subjects = [Record];
let Subjects = SubjectList<[Record]>;
}
def WarnUnusedResult : InheritableAttr {

View File

@ -2336,13 +2336,6 @@ static void handleSentinelAttr(Sema &S, Decl *D, const AttributeList &Attr) {
Attr.getAttributeSpellingListIndex()));
}
static void handleWarnUnusedAttr(Sema &S, Decl *D, const AttributeList &Attr) {
if (RecordDecl *RD = dyn_cast<RecordDecl>(D))
RD->addAttr(::new (S.Context) WarnUnusedAttr(Attr.getRange(), S.Context));
else
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
}
static void handleWarnUnusedResult(Sema &S, Decl *D, const AttributeList &Attr) {
if (!isFunction(D) && !isa<ObjCMethodDecl>(D) && !isa<CXXRecordDecl>(D)) {
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
@ -4314,8 +4307,7 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
handleVisibilityAttr(S, D, Attr, true);
break;
case AttributeList::AT_WarnUnused:
handleWarnUnusedAttr(S, D, Attr);
break;
handleSimpleAttribute<WarnUnusedAttr>(S, D, Attr); break;
case AttributeList::AT_WarnUnusedResult: handleWarnUnusedResult(S, D, Attr);
break;
case AttributeList::AT_Weak: handleWeakAttr (S, D, Attr); break;

View File

@ -1,20 +1,20 @@
// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -verify %s
struct __attribute__((warn_unused)) Test
{
Test();
~Test();
void use();
struct __attribute__((warn_unused)) Test {
Test();
~Test();
void use();
};
struct TestNormal
{
TestNormal();
struct TestNormal {
TestNormal();
};
int main()
{
Test unused; // expected-warning {{unused variable 'unused'}}
Test used;
TestNormal normal;
used.use();
int main(void) {
Test unused; // expected-warning {{unused variable 'unused'}}
Test used;
TestNormal normal;
used.use();
int i __attribute__((warn_unused)) = 12; // expected-warning {{'warn_unused' attribute only applies to struct, union or class}}
return i;
}