blob: 4b00ab293b7bc0ad9e632defd3d2160c77a193ee [file] [log] [blame]
Gabor Horvathb3856d62017-04-06 09:56:42 +00001//===--- ForwardingReferenceOverloadCheck.h - clang-tidy---------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Alexander Kornienkoa1a29332018-02-28 14:47:20 +000010#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FORWARDINGREFERENCEOVERLOADCHECK_H
11#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FORWARDINGREFERENCEOVERLOADCHECK_H
Gabor Horvathb3856d62017-04-06 09:56:42 +000012
13#include "../ClangTidy.h"
14
15namespace clang {
16namespace tidy {
Alexander Kornienkoa1a29332018-02-28 14:47:20 +000017namespace bugprone {
Gabor Horvathb3856d62017-04-06 09:56:42 +000018
19/// The checker looks for constructors that can act as copy or move constructors
20/// through their forwarding reference parameters. If a non const lvalue
21/// reference is passed to the constructor, the forwarding reference parameter
22/// can be a perfect match while the const reference parameter of the copy
23/// constructor can't. The forwarding reference constructor will be called,
24/// which can lead to confusion.
25/// For detailed description of this problem see: Scott Meyers, Effective Modern
26/// C++ Design, item 26.
27///
28/// For the user-facing documentation see:
Alexander Kornienkoa1a29332018-02-28 14:47:20 +000029/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-forwarding-reference-overload.html
Gabor Horvathb3856d62017-04-06 09:56:42 +000030class ForwardingReferenceOverloadCheck : public ClangTidyCheck {
31public:
32 ForwardingReferenceOverloadCheck(StringRef Name, ClangTidyContext *Context)
33 : ClangTidyCheck(Name, Context) {}
34 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
35 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
36};
37
Alexander Kornienkoa1a29332018-02-28 14:47:20 +000038} // namespace bugprone
Gabor Horvathb3856d62017-04-06 09:56:42 +000039} // namespace tidy
40} // namespace clang
41
Alexander Kornienkoa1a29332018-02-28 14:47:20 +000042#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FORWARDINGREFERENCEOVERLOADCHECK_H