Debian Codegraph @

clang-tools-extra/test/clang-tidy/checkers/fuchsia/trailing-return.cpp

raw
1 // RUN: %check_clang_tidy -std=c++17-or-later %s fuchsia-trailing-return %t
2
3 int add_one(const int arg) { return arg; }
4
5 auto get_add_one() -> int (*)(const int) {
6 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: a trailing return type is disallowed for this function declaration
7 // CHECK-NEXT: auto get_add_one() -> int (*)(const int) {
8 return add_one;
9 }
10
11 auto lambda = [](double x, double y) {return x + y;};
12
13 auto lambda2 = [](double x, double y) -> double {return x + y;};
14
15 int main() {
16 get_add_one()(5);
17 return 0;
18 }
19
20 template <typename T1, typename T2>
21 auto fn(const T1 &lhs, const T2 &rhs) -> decltype(lhs + rhs) {
22 return lhs + rhs;
23 }
24
25 // Now check that implicit and explicit C++17 deduction guides don't trigger this warning (PR#47614).
26
27 template <typename T>
28 struct ImplicitDeductionGuides {
29 ImplicitDeductionGuides(const T &);
30 };
31
32 template <typename A, typename B>
33 struct pair {
34 A first;
35 B second;
36 };
37
38 template <typename T>
39 struct UserDefinedDeductionGuides {
40 UserDefinedDeductionGuides(T);
41 template <typename T1, typename T2>
42 UserDefinedDeductionGuides(T1, T2);
43 };
44
45 template <typename T1, typename T2>
46 UserDefinedDeductionGuides(T1, T2) -> UserDefinedDeductionGuides<pair<T1, T2>>;
47
48 void foo() {
49 ImplicitDeductionGuides X(42);
50 UserDefinedDeductionGuides s(1, "abc");
51 }