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 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,17 +163,19 @@ // 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 @@ -176,6 +184,26 @@ 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 {