[clang-tools-extra] r222751 - clang-tidy: Add override before the first attribute.

Daniel Jasper djasper at google.com
Tue Nov 25 02:45:23 PST 2014


Author: djasper
Date: Tue Nov 25 04:45:23 2014
New Revision: 222751

URL: http://llvm.org/viewvc/llvm-project?rev=222751&view=rev
Log:
clang-tidy: Add override before the first attribute.

Apparently attributes aren't sorted by source location.

Modified:
    clang-tools-extra/trunk/clang-tidy/misc/UseOverride.cpp
    clang-tools-extra/trunk/test/clang-tidy/misc-use-override.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/UseOverride.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UseOverride.cpp?rev=222751&r1=222750&r2=222751&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UseOverride.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UseOverride.cpp Tue Nov 25 04:45:23 2014
@@ -98,8 +98,10 @@ void UseOverride::check(const MatchFinde
     if (Method->hasAttrs()) {
       for (const clang::Attr *A : Method->getAttrs()) {
         if (!A->isImplicit()) {
-          InsertLoc = Sources.getExpansionLoc(A->getLocation());
-          break;
+          SourceLocation Loc = Sources.getExpansionLoc(A->getLocation());
+          if (!InsertLoc.isValid() ||
+              Sources.isBeforeInTranslationUnit(Loc, InsertLoc))
+            InsertLoc = Loc;
         }
       }
     }

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-use-override.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-use-override.cpp?rev=222751&r1=222750&r2=222751&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-use-override.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-use-override.cpp Tue Nov 25 04:45:23 2014
@@ -9,6 +9,7 @@
 #define NOT_OVERRIDE
 
 #define MUST_USE_RESULT __attribute__((warn_unused_result))
+#define UNUSED __attribute__((unused))
 
 struct MUST_USE_RESULT MustUseResultObject {};
 
@@ -24,7 +25,7 @@ struct Base {
 
   virtual void j() const;
   virtual MustUseResultObject k();
-  virtual bool l() MUST_USE_RESULT;
+  virtual bool l() MUST_USE_RESULT UNUSED;
 
   virtual void m();
 };
@@ -71,9 +72,9 @@ public:
   // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: Prefer using
   // CHECK-FIXES: {{^  MustUseResultObject k\(\) override;}}
 
-  virtual bool l() MUST_USE_RESULT; // Has an explicit attribute
+  virtual bool l() MUST_USE_RESULT UNUSED;
   // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Prefer using
-  // CHECK-FIXES: {{^  bool l\(\) override MUST_USE_RESULT;}}
+  // CHECK-FIXES: {{^  bool l\(\) override MUST_USE_RESULT UNUSED;}}
 
   virtual void m() override final;
   // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Annotate this
@@ -117,9 +118,9 @@ public:
   // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Annotate this
   // CHECK-FIXES: {{^  void j\(\) const final;}}
 
-  virtual bool l() final MUST_USE_RESULT;
+  virtual bool l() final MUST_USE_RESULT UNUSED;
   // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Annotate this
-  // CHECK-FIXES: {{^  bool l\(\) final MUST_USE_RESULT;}}
+  // CHECK-FIXES: {{^  bool l\(\) final MUST_USE_RESULT UNUSED;}}
 };
 
 struct InlineDefinitions : public Base {
@@ -152,9 +153,9 @@ public:
   // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: Prefer using
   // CHECK-FIXES: {{^  MustUseResultObject k\(\) override {}}}
 
-  virtual bool l() MUST_USE_RESULT {} // Has an explicit attribute
+  virtual bool l() MUST_USE_RESULT UNUSED {}
   // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Prefer using
-  // CHECK-FIXES: {{^  bool l\(\) override MUST_USE_RESULT {}}}
+  // CHECK-FIXES: {{^  bool l\(\) override MUST_USE_RESULT UNUSED {}}}
 };
 
 struct Macros : public Base {





More information about the cfe-commits mailing list