From 74e3700e2abd57226c74b27b194810c515538674 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Wed, 27 Nov 2013 16:59:17 +0000 Subject: [PATCH] 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." git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195851 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/Attr.td | 2 +- lib/Sema/SemaDeclAttr.cpp | 10 +-------- test/SemaCXX/warn-unused-attribute.cpp | 28 +++++++++++++------------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td index 6802c86aae..29addcb618 100644 --- a/include/clang/Basic/Attr.td +++ b/include/clang/Basic/Attr.td @@ -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 { diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 57b8eba6af..a8d336e229 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -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(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(D) && !isa(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(S, D, Attr); break; case AttributeList::AT_WarnUnusedResult: handleWarnUnusedResult(S, D, Attr); break; case AttributeList::AT_Weak: handleWeakAttr (S, D, Attr); break; diff --git a/test/SemaCXX/warn-unused-attribute.cpp b/test/SemaCXX/warn-unused-attribute.cpp index 72f96eea0b..f52de3b931 100644 --- a/test/SemaCXX/warn-unused-attribute.cpp +++ b/test/SemaCXX/warn-unused-attribute.cpp @@ -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; } -- 2.40.0