[clang-tools-extra] r367785 - [clang-tidy] Add FixItHint for performance-noexcept-move-constructor
Zinovy Nis via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 4 06:32:39 PDT 2019
Author: zinovy.nis
Date: Sun Aug 4 06:32:39 2019
New Revision: 367785
URL: http://llvm.org/viewvc/llvm-project?rev=367785&view=rev
Log:
[clang-tidy] Add FixItHint for performance-noexcept-move-constructor
Differential Revision: https://reviews.llvm.org/D65104
Added:
clang-tools-extra/trunk/test/clang-tidy/performance-noexcept-move-constructor-fix.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp
Modified: clang-tools-extra/trunk/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp?rev=367785&r1=367784&r2=367785&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp Sun Aug 4 06:32:39 2019
@@ -9,6 +9,7 @@
#include "NoexceptMoveConstructorCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Tooling/FixIt.h"
using namespace clang::ast_matchers;
@@ -47,9 +48,20 @@ void NoexceptMoveConstructorCheck::check
return;
if (!isNoexceptExceptionSpec(ProtoType->getExceptionSpecType())) {
- diag(Decl->getLocation(), "move %0s should be marked noexcept")
+ auto Diag =
+ diag(Decl->getLocation(), "move %0s should be marked noexcept")
<< MethodType;
- // FIXME: Add a fixit.
+ // Add FixIt hints.
+ SourceManager &SM = *Result.SourceManager;
+ assert(Decl->getNumParams() > 0);
+ SourceLocation NoexceptLoc = Decl->getParamDecl(Decl->getNumParams() - 1)
+ ->getSourceRange()
+ .getEnd();
+ if (NoexceptLoc.isValid())
+ NoexceptLoc = Lexer::findLocationAfterToken(
+ NoexceptLoc, tok::r_paren, SM, Result.Context->getLangOpts(), true);
+ if (NoexceptLoc.isValid())
+ Diag << FixItHint::CreateInsertion(NoexceptLoc, " noexcept ");
return;
}
Added: clang-tools-extra/trunk/test/clang-tidy/performance-noexcept-move-constructor-fix.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/performance-noexcept-move-constructor-fix.cpp?rev=367785&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/performance-noexcept-move-constructor-fix.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/performance-noexcept-move-constructor-fix.cpp Sun Aug 4 06:32:39 2019
@@ -0,0 +1,67 @@
+// RUN: %check_clang_tidy %s performance-noexcept-move-constructor %t
+
+struct C_1 {
+ ~C_1() {}
+ C_1(int a) {}
+ C_1(C_1&& a) :C_1(5) {}
+ // CHECK-FIXES: ){{.*}}noexcept{{.*}}:
+ C_1& operator=(C_1&&) { return *this; }
+ // CHECK-FIXES: ){{.*}}noexcept{{.*}} {
+};
+
+struct C_2 {
+ ~C_2() {}
+ C_2(C_2&& a);
+// CHECK-FIXES: ){{.*}}noexcept{{.*}};
+ C_2& operator=(C_2&&);
+// CHECK-FIXES: ){{.*}}noexcept{{.*}};
+};
+
+C_2::C_2(C_2&& a) {}
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} {}
+C_2& C_2::operator=(C_2&&) { return *this; }
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} {
+
+struct C_3 {
+ ~C_3() {}
+ C_3(C_3&& a);
+// CHECK-FIXES: ){{.*}}noexcept{{.*}};
+ C_3& operator=(C_3&& a);
+// CHECK-FIXES: ){{.*}}noexcept{{.*}};
+};
+
+C_3::C_3(C_3&& a) = default;
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} = default;
+C_3& C_3::operator=(C_3&& a) = default;
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} = default;
+
+template <class T>
+struct C_4 {
+ C_4(C_4<T>&&) {}
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} {}
+ ~C_4() {}
+ C_4& operator=(C_4&& a) = default;
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} = default;
+};
+
+template <class T>
+struct C_5 {
+ C_5(C_5<T>&&) {}
+// CHECK-FIXES:){{.*}}noexcept{{.*}} {}
+ ~C_5() {}
+ auto operator=(C_5&& a)->C_5<T> = default;
+// CHECK-FIXES:){{.*}}noexcept{{.*}} = default;
+};
+
+template <class T>
+struct C_6 {
+ C_6(C_6<T>&&) {}
+// CHECK-FIXES:){{.*}}noexcept{{.*}} {}
+ ~C_6() {}
+ auto operator=(C_6&& a)->C_6<T>;
+// CHECK-FIXES:){{.*}}noexcept{{.*}};
+};
+
+template <class T>
+auto C_6<T>::operator=(C_6<T>&& a) -> C_6<T> {}
+// CHECK-FIXES: ){{.*}}noexcept{{.*}} {}
\ No newline at end of file
More information about the cfe-commits
mailing list