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()->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")) + if (const auto *D = Result.Nodes.getNodeAs("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/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -140,6 +140,9 @@ ` 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 + ` for C++17 deduction guides. + Removed checks ^^^^^^^^^^^^^^ 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 +struct ImplicitDeductionGuides { + ImplicitDeductionGuides(const T &); +}; + +template +struct pair { + A first; + B second; +}; + +template +struct UserDefinedDeductionGuides { + UserDefinedDeductionGuides(T); + template + UserDefinedDeductionGuides(T1, T2); +}; + +template +UserDefinedDeductionGuides(T1, T2) -> UserDefinedDeductionGuides>; + +void foo() { + ImplicitDeductionGuides X(42); + UserDefinedDeductionGuides s(1, "abc"); +}