From bf5bd94142ba254c32ac3549d203c101da0e6f10 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Tue, 26 May 2015 14:35:09 +0000 Subject: [PATCH] [clang-tidy] misc-noexcept-move-ctors should ignore implicit constructors and assignments. llvm-svn: 238202 --- clang-tools-extra/clang-tidy/misc/NoexceptMoveCtorsCheck.cpp | 3 ++- clang-tools-extra/clang-tidy/misc/NoexceptMoveCtorsCheck.h | 6 +++--- clang-tools-extra/test/clang-tidy/misc-noexcept-move-ctors.cpp | 8 ++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/clang-tidy/misc/NoexceptMoveCtorsCheck.cpp b/clang-tools-extra/clang-tidy/misc/NoexceptMoveCtorsCheck.cpp index 3b74b8a..b33e908 100644 --- a/clang-tools-extra/clang-tidy/misc/NoexceptMoveCtorsCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/NoexceptMoveCtorsCheck.cpp @@ -18,7 +18,8 @@ namespace tidy { void NoexceptMoveCtorsCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( - methodDecl(anyOf(constructorDecl(), hasOverloadedOperatorName("="))) + methodDecl(anyOf(constructorDecl(), hasOverloadedOperatorName("=")), + unless(isImplicit()), unless(isDeleted())) .bind("decl"), this); } diff --git a/clang-tools-extra/clang-tidy/misc/NoexceptMoveCtorsCheck.h b/clang-tools-extra/clang-tidy/misc/NoexceptMoveCtorsCheck.h index 3e5b0bb..0e3747c 100644 --- a/clang-tools-extra/clang-tidy/misc/NoexceptMoveCtorsCheck.h +++ b/clang-tools-extra/clang-tidy/misc/NoexceptMoveCtorsCheck.h @@ -15,9 +15,9 @@ namespace clang { namespace tidy { -/// \brief The check flags move constructors and assignment operators not marked -/// with \c noexcept or marked with \c noexcept(expr) where \c expr evaluates to -/// \c false (but is not a \c false literal itself). +/// \brief The check flags user-defined move constructors and assignment +/// operators not marked with \c noexcept or marked with \c noexcept(expr) where +/// \c expr evaluates to \c false (but is not a \c false literal itself). /// /// Move constructors of all the types used with STL containers, for example, /// need to be declared \c noexcept. Otherwise STL will choose copy constructors diff --git a/clang-tools-extra/test/clang-tidy/misc-noexcept-move-ctors.cpp b/clang-tools-extra/test/clang-tidy/misc-noexcept-move-ctors.cpp index b4be26f..a69c639 100644 --- a/clang-tools-extra/test/clang-tidy/misc-noexcept-move-ctors.cpp +++ b/clang-tools-extra/test/clang-tidy/misc-noexcept-move-ctors.cpp @@ -14,6 +14,13 @@ struct B { // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: noexcept specifier on the move constructor evaluates to 'false' [misc-noexcept-move-ctors] }; +class OK {}; + +void f() { + OK a; + a = OK(); +} + class OK1 { public: OK1(); @@ -34,4 +41,5 @@ public: struct OK3 { OK3(OK3 &&) noexcept(false) {} + OK3 &operator=(OK3 &&) = delete; }; -- 2.7.4