r195851 - 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."

Aaron Ballman aaron at aaronballman.com
Wed Nov 27 08:59:17 PST 2013


Author: aaronballman
Date: Wed Nov 27 10:59:17 2013
New Revision: 195851

URL: http://llvm.org/viewvc/llvm-project?rev=195851&view=rev
Log:
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."

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

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=195851&r1=195850&r2=195851&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed Nov 27 10:59:17 2013
@@ -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 {

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=195851&r1=195850&r2=195851&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Nov 27 10:59:17 2013
@@ -2336,13 +2336,6 @@ static void handleSentinelAttr(Sema &S,
                           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
     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;

Modified: cfe/trunk/test/SemaCXX/warn-unused-attribute.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-attribute.cpp?rev=195851&r1=195850&r2=195851&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-unused-attribute.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-attribute.cpp Wed Nov 27 10:59:17 2013
@@ -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;
 }





More information about the cfe-commits mailing list