[PATCH] D9286: Insert override at the same line as the end of the function declaration
Ehsan Akhgari via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 18 19:06:31 PDT 2015
This revision was automatically updated to reflect the committed changes.
Closed by commit rL245401: Insert override at the same line as the end of the function declaration (authored by ehsan).
Changed prior to commit:
http://reviews.llvm.org/D9286?vs=24449&id=32492#toc
Repository:
rL LLVM
http://reviews.llvm.org/D9286
Files:
clang-tools-extra/trunk/clang-tidy/misc/UseOverrideCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-use-override.cpp
Index: clang-tools-extra/trunk/test/clang-tidy/misc-use-override.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-use-override.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/misc-use-override.cpp
@@ -32,6 +32,12 @@
virtual void m();
virtual void m2();
virtual void o() __attribute__((unused));
+
+ virtual void r() &;
+ virtual void rr() &&;
+
+ virtual void cv() const volatile;
+ virtual void cv2() const volatile;
};
struct SimpleCases : public Base {
@@ -157,25 +163,47 @@
// CHECK-MESSAGES-NOT: warning:
// CHECK-FIXES: {{^}} void b() override {}
- virtual void c() {}
- // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
- // CHECK-FIXES: {{^}} void c() override {}
+ virtual void c()
+ {}
+ // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void c() override
virtual void d() override {}
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'virtual' is redundant
// CHECK-FIXES: {{^}} void d() override {}
- virtual void j() const {}
- // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
- // CHECK-FIXES: {{^}} void j() const override {}
+ virtual void j() const
+ {}
+ // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void j() const override
virtual MustUseResultObject k() {} // Has an implicit attribute.
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: prefer using
// CHECK-FIXES: {{^}} MustUseResultObject k() override {}
virtual bool l() MUST_USE_RESULT UNUSED {}
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using
// CHECK-FIXES: {{^}} bool l() override MUST_USE_RESULT UNUSED {}
+
+ virtual void r() &
+ {}
+ // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void r() & override
+
+ virtual void rr() &&
+ {}
+ // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void rr() && override
+
+ virtual void cv() const volatile
+ {}
+ // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void cv() const volatile override
+
+ virtual void cv2() const volatile // some comment
+ {}
+ // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: prefer using
+ // CHECK-FIXES: {{^}} void cv2() const volatile override // some comment
};
struct Macros : public Base {
Index: clang-tools-extra/trunk/clang-tidy/misc/UseOverrideCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UseOverrideCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/misc/UseOverrideCheck.cpp
@@ -140,8 +140,20 @@
}
if (InsertLoc.isInvalid() && Method->doesThisDeclarationHaveABody() &&
- Method->getBody() && !Method->isDefaulted())
- InsertLoc = Method->getBody()->getLocStart();
+ Method->getBody() && !Method->isDefaulted()) {
+ // For methods with inline definition, add the override keyword at the
+ // end of the declaration of the function, but prefer to put it on the
+ // same line as the declaration if the beginning brace for the start of
+ // the body falls on the next line.
+ Token LastNonCommentToken;
+ for (Token T : Tokens) {
+ if (!T.is(tok::comment)) {
+ LastNonCommentToken = T;
+ }
+ }
+ InsertLoc = LastNonCommentToken.getEndLoc();
+ ReplacementText = " override";
+ }
if (!InsertLoc.isValid()) {
// For declarations marked with "= 0" or "= [default|delete]", the end
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9286.32492.patch
Type: text/x-patch
Size: 3586 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150819/94957cb7/attachment.bin>
More information about the cfe-commits
mailing list