]> granicus.if.org Git - clang/commitdiff
Enabling the subject list for the warn_unused attribute, and adding a test case....
authorAaron Ballman <aaron@aaronballman.com>
Wed, 27 Nov 2013 16:59:17 +0000 (16:59 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Wed, 27 Nov 2013 16:59:17 +0000 (16:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195851 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Attr.td
lib/Sema/SemaDeclAttr.cpp
test/SemaCXX/warn-unused-attribute.cpp

index 6802c86aae6dd024a9f6a7f2117c342dcf3ca400..29addcb618963a8a74092e71c90e1ade0cef8191 100644 (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 {
index 57b8eba6afa25a2f278fa8b839ba6a3f4c33e83b..a8d336e2293cc13dadc5f7c737cf43e50a3615bb 100644 (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;
index 72f96eea0b31974302b41d295f2c573f834ab0a9..f52de3b931b0c8c17471105714adbaeb75eb8fe0 100644 (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;
 }