[clang-tidy] Fix false positive in `readability-named-parameter` for defaulted out...
authorAMS21 <AMS21.github@gmail.com>
Tue, 13 Jun 2023 17:58:16 +0000 (17:58 +0000)
committerPiotr Zegar <me@piotrzegar.pl>
Tue, 13 Jun 2023 18:13:52 +0000 (18:13 +0000)
This fixes llvm#63056

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D152825

clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/readability/named-parameter.cpp

index f621cfe..ea6597d 100644 (file)
@@ -28,7 +28,7 @@ void NamedParameterCheck::check(const MatchFinder::MatchResult &Result) {
   // overriden method.
   const FunctionDecl *Definition = nullptr;
   if ((!Function->isDefined(Definition) || Function->isDefaulted() ||
-       Function->isDeleted()) &&
+       Definition->isDefaulted() || Function->isDeleted()) &&
       (!isa<CXXMethodDecl>(Function) ||
        cast<CXXMethodDecl>(Function)->size_overridden_methods() == 0))
     return;
index 7cb9664..cb9b961 100644 (file)
@@ -396,6 +396,10 @@ Changes in existing checks
   <clang-tidy/checks/readability/misleading-indentation>` check when warning would
   be unnecessarily emitted for template dependent ``if constexpr``.
 
+- Fixed a false positive in :doc:`readability-named-parameter
+  <clang-tidy/checks/readability/named-parameter>` for defaulted out-of-line
+  special member functions.
+
 - Fixed incorrect fixes in :doc:`readability-redundant-declaration
   <clang-tidy/checks/readability/redundant-declaration>` check when linkage
   (like ``extern "C"``) is explicitly specified.
index af2c195..8c6fb12 100644 (file)
@@ -131,3 +131,20 @@ void f(std::nullptr_t) {}
 typedef void (F)(int);
 F f;
 void f(int x) {}
+
+namespace issue_63056
+{
+  struct S {
+    S(const S&);
+    S(S&&);
+
+    S& operator=(const S&);
+    S& operator=(S&&);
+  };
+
+  S::S(const S&) = default;
+  S::S(S&&) = default;
+
+  S& S::operator=(const S&) = default;
+  S& S::operator=(S&&) = default;
+} // namespace issue_63056