fwolff updated this revision to Diff 391102.
fwolff added a comment.

In D113828#3164016 <https://reviews.llvm.org/D113828#3164016>, @aaron.ballman 
wrote:

> LGTM! Can you add a release note about the bug fix?

Done. Thank you for the review! Can you also commit it for me? You can use name 
and email as in `6259016361345e09f0607ef4e037e00bcbe4bd40`. Thanks!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113828/new/

https://reviews.llvm.org/D113828

Files:
  clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/fuchsia-trailing-return.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/fuchsia-trailing-return.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/fuchsia-trailing-return.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/fuchsia-trailing-return.cpp
@@ -1,9 +1,9 @@
-// RUN: %check_clang_tidy %s fuchsia-trailing-return %t
+// RUN: %check_clang_tidy -std=c++17-or-later %s fuchsia-trailing-return %t
 
 int add_one(const int arg) { return arg; }
 
 auto get_add_one() -> int (*)(const int) {
-  // CHECK-MESSAGES: [[@LINE-1]]:1: warning: a trailing return type is 
disallowed for this type of declaration
+  // CHECK-MESSAGES: [[@LINE-1]]:1: warning: a trailing return type is 
disallowed for this function declaration
   // CHECK-NEXT: auto get_add_one() -> int (*)(const int) {
   return add_one;
 }
@@ -21,3 +21,31 @@
 auto fn(const T1 &lhs, const T2 &rhs) -> decltype(lhs + rhs) {
   return lhs + rhs;
 }
+
+// Now check that implicit and explicit C++17 deduction guides don't trigger 
this warning (PR#47614).
+
+template <typename T>
+struct ImplicitDeductionGuides {
+  ImplicitDeductionGuides(const T &);
+};
+
+template <typename A, typename B>
+struct pair {
+  A first;
+  B second;
+};
+
+template <typename T>
+struct UserDefinedDeductionGuides {
+  UserDefinedDeductionGuides(T);
+  template <typename T1, typename T2>
+  UserDefinedDeductionGuides(T1, T2);
+};
+
+template <typename T1, typename T2>
+UserDefinedDeductionGuides(T1, T2) -> UserDefinedDeductionGuides<pair<T1, T2>>;
+
+void foo() {
+  ImplicitDeductionGuides X(42);
+  UserDefinedDeductionGuides s(1, "abc");
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -140,6 +140,9 @@
   <clang-tidy/checks/google-readability-casting>` to diagnose and fix 
functional
   casts, to achieve feature parity with the corresponding ``cpplint.py`` check.
 
+- Fixed a false positive in :doc:`fuchsia-trailing-return
+  <clang-tidy/checks/fuchsia-trailing-return>` for C++17 deduction guides.
+
 Removed checks
 ^^^^^^^^^^^^^^
 
Index: clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp
+++ clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp
@@ -17,12 +17,6 @@
 namespace tidy {
 namespace fuchsia {
 
-namespace {
-AST_MATCHER(FunctionDecl, hasTrailingReturn) {
-  return Node.getType()->castAs<FunctionProtoType>()->hasTrailingReturn();
-}
-} // namespace
-
 void TrailingReturnCheck::registerMatchers(MatchFinder *Finder) {
   // Functions that have trailing returns are disallowed, except for those
   // using decltype specifiers and lambda with otherwise unutterable
@@ -30,15 +24,16 @@
   Finder->addMatcher(
       functionDecl(hasTrailingReturn(),
                    unless(anyOf(returns(decltypeType()),
-                                hasParent(cxxRecordDecl(isLambda())))))
+                                hasParent(cxxRecordDecl(isLambda())),
+                                cxxDeductionGuideDecl())))
           .bind("decl"),
       this);
 }
 
 void TrailingReturnCheck::check(const MatchFinder::MatchResult &Result) {
-  if (const auto *D = Result.Nodes.getNodeAs<Decl>("decl"))
+  if (const auto *D = Result.Nodes.getNodeAs<FunctionDecl>("decl"))
     diag(D->getBeginLoc(),
-         "a trailing return type is disallowed for this type of declaration");
+         "a trailing return type is disallowed for this function declaration");
 }
 
 } // namespace fuchsia


Index: clang-tools-extra/test/clang-tidy/checkers/fuchsia-trailing-return.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/fuchsia-trailing-return.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/fuchsia-trailing-return.cpp
@@ -1,9 +1,9 @@
-// RUN: %check_clang_tidy %s fuchsia-trailing-return %t
+// RUN: %check_clang_tidy -std=c++17-or-later %s fuchsia-trailing-return %t
 
 int add_one(const int arg) { return arg; }
 
 auto get_add_one() -> int (*)(const int) {
-  // CHECK-MESSAGES: [[@LINE-1]]:1: warning: a trailing return type is disallowed for this type of declaration
+  // CHECK-MESSAGES: [[@LINE-1]]:1: warning: a trailing return type is disallowed for this function declaration
   // CHECK-NEXT: auto get_add_one() -> int (*)(const int) {
   return add_one;
 }
@@ -21,3 +21,31 @@
 auto fn(const T1 &lhs, const T2 &rhs) -> decltype(lhs + rhs) {
   return lhs + rhs;
 }
+
+// Now check that implicit and explicit C++17 deduction guides don't trigger this warning (PR#47614).
+
+template <typename T>
+struct ImplicitDeductionGuides {
+  ImplicitDeductionGuides(const T &);
+};
+
+template <typename A, typename B>
+struct pair {
+  A first;
+  B second;
+};
+
+template <typename T>
+struct UserDefinedDeductionGuides {
+  UserDefinedDeductionGuides(T);
+  template <typename T1, typename T2>
+  UserDefinedDeductionGuides(T1, T2);
+};
+
+template <typename T1, typename T2>
+UserDefinedDeductionGuides(T1, T2) -> UserDefinedDeductionGuides<pair<T1, T2>>;
+
+void foo() {
+  ImplicitDeductionGuides X(42);
+  UserDefinedDeductionGuides s(1, "abc");
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -140,6 +140,9 @@
   <clang-tidy/checks/google-readability-casting>` to diagnose and fix functional
   casts, to achieve feature parity with the corresponding ``cpplint.py`` check.
 
+- Fixed a false positive in :doc:`fuchsia-trailing-return
+  <clang-tidy/checks/fuchsia-trailing-return>` for C++17 deduction guides.
+
 Removed checks
 ^^^^^^^^^^^^^^
 
Index: clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp
+++ clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp
@@ -17,12 +17,6 @@
 namespace tidy {
 namespace fuchsia {
 
-namespace {
-AST_MATCHER(FunctionDecl, hasTrailingReturn) {
-  return Node.getType()->castAs<FunctionProtoType>()->hasTrailingReturn();
-}
-} // namespace
-
 void TrailingReturnCheck::registerMatchers(MatchFinder *Finder) {
   // Functions that have trailing returns are disallowed, except for those
   // using decltype specifiers and lambda with otherwise unutterable
@@ -30,15 +24,16 @@
   Finder->addMatcher(
       functionDecl(hasTrailingReturn(),
                    unless(anyOf(returns(decltypeType()),
-                                hasParent(cxxRecordDecl(isLambda())))))
+                                hasParent(cxxRecordDecl(isLambda())),
+                                cxxDeductionGuideDecl())))
           .bind("decl"),
       this);
 }
 
 void TrailingReturnCheck::check(const MatchFinder::MatchResult &Result) {
-  if (const auto *D = Result.Nodes.getNodeAs<Decl>("decl"))
+  if (const auto *D = Result.Nodes.getNodeAs<FunctionDecl>("decl"))
     diag(D->getBeginLoc(),
-         "a trailing return type is disallowed for this type of declaration");
+         "a trailing return type is disallowed for this function declaration");
 }
 
 } // namespace fuchsia
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to