193a88e33SJulie Hockett //===--- TrailingReturnCheck.cpp - clang-tidy------------------------------===// 293a88e33SJulie Hockett // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 693a88e33SJulie Hockett // 793a88e33SJulie Hockett //===----------------------------------------------------------------------===// 893a88e33SJulie Hockett 993a88e33SJulie Hockett #include "TrailingReturnCheck.h" 1093a88e33SJulie Hockett #include "clang/AST/ASTContext.h" 1193a88e33SJulie Hockett #include "clang/ASTMatchers/ASTMatchFinder.h" 1293a88e33SJulie Hockett #include "clang/ASTMatchers/ASTMatchersInternal.h" 1393a88e33SJulie Hockett 1493a88e33SJulie Hockett using namespace clang::ast_matchers; 1593a88e33SJulie Hockett 16*7d2ea6c4SCarlos Galvez namespace clang::tidy::fuchsia { 1793a88e33SJulie Hockett registerMatchers(MatchFinder * Finder)1893a88e33SJulie Hockettvoid TrailingReturnCheck::registerMatchers(MatchFinder *Finder) { 1993a88e33SJulie Hockett // Functions that have trailing returns are disallowed, except for those 2093a88e33SJulie Hockett // using decltype specifiers and lambda with otherwise unutterable 2193a88e33SJulie Hockett // return types. 2293a88e33SJulie Hockett Finder->addMatcher( 23976e0c07SAlexander Kornienko functionDecl(hasTrailingReturn(), 2493a88e33SJulie Hockett unless(anyOf(returns(decltypeType()), 25844a8d3cSFabian Wolff hasParent(cxxRecordDecl(isLambda())), 26844a8d3cSFabian Wolff cxxDeductionGuideDecl()))) 2793a88e33SJulie Hockett .bind("decl"), 2893a88e33SJulie Hockett this); 2993a88e33SJulie Hockett } 3093a88e33SJulie Hockett check(const MatchFinder::MatchResult & Result)3193a88e33SJulie Hockettvoid TrailingReturnCheck::check(const MatchFinder::MatchResult &Result) { 32844a8d3cSFabian Wolff if (const auto *D = Result.Nodes.getNodeAs<FunctionDecl>("decl")) 3343465bf3SStephen Kelly diag(D->getBeginLoc(), 34844a8d3cSFabian Wolff "a trailing return type is disallowed for this function declaration"); 3593a88e33SJulie Hockett } 3693a88e33SJulie Hockett 37*7d2ea6c4SCarlos Galvez } // namespace clang::tidy::fuchsia 38