summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/fuchsia
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clang-tidy/fuchsia')
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt1
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp3
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp56
-rw-r--r--clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.h37
4 files changed, 97 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt b/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt
index 28e4b0e781a..25da139495e 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt
@@ -5,6 +5,7 @@ add_clang_library(clangTidyFuchsiaModule
FuchsiaTidyModule.cpp
OverloadedOperatorCheck.cpp
StaticallyConstructedObjectsCheck.cpp
+ TrailingReturnCheck.cpp
VirtualInheritanceCheck.cpp
LINK_LIBS
diff --git a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
index ab4aaff9695..0eed7407490 100644
--- a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
@@ -13,6 +13,7 @@
#include "DefaultArgumentsCheck.h"
#include "OverloadedOperatorCheck.h"
#include "StaticallyConstructedObjectsCheck.h"
+#include "TrailingReturnCheck.h"
#include "VirtualInheritanceCheck.h"
using namespace clang::ast_matchers;
@@ -31,6 +32,8 @@ public:
"fuchsia-overloaded-operator");
CheckFactories.registerCheck<StaticallyConstructedObjectsCheck>(
"fuchsia-statically-constructed-objects");
+ CheckFactories.registerCheck<TrailingReturnCheck>(
+ "fuchsia-trailing-return");
CheckFactories.registerCheck<VirtualInheritanceCheck>(
"fuchsia-virtual-inheritance");
}
diff --git a/clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp
new file mode 100644
index 00000000000..27989d9bba1
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.cpp
@@ -0,0 +1,56 @@
+//===--- TrailingReturnCheck.cpp - clang-tidy------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "TrailingReturnCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace ast_matchers {
+
+const internal::VariadicDynCastAllOfMatcher<Type, DecltypeType> decltypeType;
+
+} // namespace ast_matchers
+
+namespace tidy {
+namespace fuchsia {
+
+AST_MATCHER(FunctionDecl, hasTrailingReturn) {
+ return Node.getType()->castAs<FunctionProtoType>()->hasTrailingReturn();
+}
+
+void TrailingReturnCheck::registerMatchers(MatchFinder *Finder) {
+
+ // Requires C++11 or later.
+ if (!getLangOpts().CPlusPlus11)
+ return;
+
+ // Functions that have trailing returns are disallowed, except for those
+ // using decltype specifiers and lambda with otherwise unutterable
+ // return types.
+ Finder->addMatcher(
+ functionDecl(allOf(hasTrailingReturn(),
+ unless(anyOf(returns(decltypeType()),
+ hasParent(cxxRecordDecl(isLambda()))))))
+ .bind("decl"),
+ this);
+}
+
+void TrailingReturnCheck::check(const MatchFinder::MatchResult &Result) {
+ if (const auto *D = Result.Nodes.getNodeAs<Decl>("decl"))
+ diag(D->getLocStart(),
+ "a trailing return type is disallowed for this type of declaration");
+}
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang
diff --git a/clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.h b/clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.h
new file mode 100644
index 00000000000..4a16c4e4ad2
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/fuchsia/TrailingReturnCheck.h
@@ -0,0 +1,37 @@
+//===--- TrailingReturnCheck.h - clang-tidy----------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_TRAILING_RETURN_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_TRAILING_RETURN_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+/// Functions that have trailing returns are disallowed, except for those
+/// using decltype specifiers and lambda with otherwise unutterable
+/// return types.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-trailing-return.html
+class TrailingReturnCheck : public ClangTidyCheck {
+public:
+ TrailingReturnCheck(StringRef Name, ClangTidyContext *Context)
+ : ClangTidyCheck(Name, Context) {}
+ void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_TRAILING_RETURN_H
OpenPOWER on IntegriCloud