1 // RUN: %check_clang_tidy %s bugprone-argument-comment %t -- \
2 // RUN:   -config="{CheckOptions: [ \
3 // RUN:     {key: bugprone-argument-comment.IgnoreSingleArgument, value: true}, \
4 // RUN:     {key: bugprone-argument-comment.CommentBoolLiterals, value: true}, \
5 // RUN:     {key: bugprone-argument-comment.CommentIntegerLiterals, value: true}, \
6 // RUN:     {key: bugprone-argument-comment.CommentFloatLiterals, value: true}, \
7 // RUN:     {key: bugprone-argument-comment.CommentUserDefinedLiterals, value: true}, \
8 // RUN:     {key: bugprone-argument-comment.CommentStringLiterals, value: true}, \
9 // RUN:     {key: bugprone-argument-comment.CommentNullPtrs, value: true}, \
10 // RUN:     {key: bugprone-argument-comment.CommentCharacterLiterals, value: true}]}" --
11 
12 struct A {
13   void foo(bool abc);
14   void foo(bool abc, bool cde);
15   void foo(const char *, bool abc);
16   void foo(int iabc);
17   void foo(float fabc);
18   void foo(double dabc);
19   void foo(const char *strabc);
20   void fooW(const wchar_t *wstrabc);
21   void fooPtr(A *ptrabc);
22   void foo(char chabc);
23 };
24 
25 #define FOO 1
26 
27 void g(int a);
28 void h(double b);
29 void i(const char *c);
30 
31 double operator"" _km(long double);
32 
test()33 void test() {
34   A a;
35 
36   a.foo(true);
37 
38   a.foo(false);
39 
40   a.foo(true, false);
41   // CHECK-MESSAGES: [[@LINE-1]]:9: warning: argument comment missing for literal argument 'abc' [bugprone-argument-comment]
42   // CHECK-MESSAGES: [[@LINE-2]]:15: warning: argument comment missing for literal argument 'cde' [bugprone-argument-comment]
43   // CHECK-FIXES: a.foo(/*abc=*/true, /*cde=*/false);
44 
45   a.foo(false, true);
46   // CHECK-MESSAGES: [[@LINE-1]]:9: warning: argument comment missing for literal argument 'abc' [bugprone-argument-comment]
47   // CHECK-MESSAGES: [[@LINE-2]]:16: warning: argument comment missing for literal argument 'cde' [bugprone-argument-comment]
48   // CHECK-FIXES: a.foo(/*abc=*/false, /*cde=*/true);
49 
50   a.foo(/*abc=*/false, true);
51   // CHECK-MESSAGES: [[@LINE-1]]:24: warning: argument comment missing for literal argument 'cde' [bugprone-argument-comment]
52   // CHECK-FIXES: a.foo(/*abc=*/false, /*cde=*/true);
53 
54   a.foo(false, /*cde=*/true);
55   // CHECK-MESSAGES: [[@LINE-1]]:9: warning: argument comment missing for literal argument 'abc' [bugprone-argument-comment]
56   // CHECK-FIXES: a.foo(/*abc=*/false, /*cde=*/true);
57 
58   bool val1 = true;
59   bool val2 = false;
60   a.foo(val1, val2);
61 
62   a.foo("", true);
63   // CHECK-MESSAGES: [[@LINE-1]]:13: warning: argument comment missing for literal argument 'abc' [bugprone-argument-comment]
64   // CHECK-FIXES: a.foo("", /*abc=*/true);
65 
66   a.foo(0);
67 
68   a.foo(1.0f);
69 
70   a.foo(1.0);
71 
72   int val3 = 10;
73   a.foo(val3);
74 
75   float val4 = 10.0;
76   a.foo(val4);
77 
78   double val5 = 10.0;
79   a.foo(val5);
80 
81   a.foo("Hello World");
82 
83   a.fooW(L"Hello World");
84 
85   a.fooPtr(nullptr);
86 
87   a.foo(402.0_km);
88 
89   a.foo('A');
90 
91   g(FOO);
92 
93   h(1.0f);
94 
95   i(__FILE__);
96 
97   g((1));
98 }
99 
100 void f(bool _with_underscores_);
ignores_underscores()101 void ignores_underscores() {
102   f(false);
103 
104   f(true);
105 }
106