1// RUN: %check_clang_tidy %s fuchsia-default-arguments-declarations %t
2
3int foo(int value = 5) { return value; }
4// CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
5// CHECK-FIXES: int foo(int value) { return value; }
6
7int bar(int value) { return value; }
8
9class Baz {
10public:
11 int a(int value = 5) { return value; }
12 // CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
13 // CHECK-FIXES: int a(int value) { return value; }
14
15 int b(int value) { return value; }
16};
17
18class Foo {
19 // Fix should be suggested in declaration
20 int a(int value = 53);
21 // CHECK-NOTES: [[@LINE-1]]:9: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
22 // CHECK-FIXES: int a(int value);
23};
24
25// Fix shouldn't be suggested in implementation
26int Foo::a(int value) {
27 return value;
28}
29
30// Elided functions
31void f(int = 5) {};
32// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
33// CHECK-FIXES: void f(int) {};
34
35void g(int) {};
36
37// Should not suggest fix for macro-defined parameters
38#define D(val) = val
39
40void h(int i D(5));
41// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
42// CHECK-FIXES-NOT: void h(int i);
43
44void x(int i);
45void x(int i = 12);
46// CHECK-NOTES: [[@LINE-1]]:8: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
47// CHECK-FIXES: void x(int i);
48
49void x(int i) {}
50
51struct S {
52 void x(int i);
53};
54
55void S::x(int i = 12) {}
56// CHECK-NOTES: [[@LINE-1]]:11: warning: declaring a parameter with a default argument is disallowed [fuchsia-default-arguments-declarations]
57// CHECK-FIXES: void S::x(int i) {}
58

source code of clang-tools-extra/test/clang-tidy/checkers/fuchsia/default-arguments-declarations.cpp