Debian Codegraph @

clang-tools-extra/test/clang-tidy/checkers/bugprone/reserved-identifier-invert.cpp

raw
1 // RUN: %check_clang_tidy %s bugprone-reserved-identifier %t -- \
2 // RUN: -config='{CheckOptions: { \
3 // RUN: bugprone-reserved-identifier.Invert: true, \
4 // RUN: bugprone-reserved-identifier.AllowedIdentifiers: "std;reference_wrapper;ref;^c?ref;type;get" \
5 // RUN: }}' -- \
6 // RUN: -I%S/Inputs/reserved-identifier \
7 // RUN: -isystem %S/Inputs/reserved-identifier/system
8
9 namespace std {
10
11 void __f() {}
12
13 void f();
14 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier 'f', which is not a reserved identifier [bugprone-reserved-identifier]
15 // CHECK-FIXES: {{^}}void __f();{{$}}
16 struct helper {};
17 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: declaration uses identifier 'helper', which is not a reserved identifier [bugprone-reserved-identifier]
18 // CHECK-FIXES: {{^}}struct __helper {};{{$}}
19 struct Helper {};
20 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: declaration uses identifier 'Helper', which is not a reserved identifier [bugprone-reserved-identifier]
21 // CHECK-FIXES: {{^}}struct _Helper {};{{$}}
22 struct _helper2 {};
23 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: declaration uses identifier '_helper2', which is not a reserved identifier [bugprone-reserved-identifier]
24 // CHECK-FIXES: {{^}}struct __helper2 {};{{$}}
25
26 template <class _Tp>
27 class reference_wrapper {
28 public:
29 typedef _Tp type;
30
31 private:
32 type *__f_;
33
34 public:
35 reference_wrapper(type &__f)
36 : __f_(&__f) {}
37 // access
38 operator type &() const { return *__f_; }
39 type &get() const { return *__f_; }
40 };
41
42 template <class _Tp>
43 inline reference_wrapper<_Tp>
44 ref(_Tp &__t) noexcept {
45 return reference_wrapper<_Tp>(__t);
46 }
47
48 template <class _Tp>
49 inline reference_wrapper<_Tp>
50 ref(reference_wrapper<_Tp> __t) noexcept {
51 return ref(__t.get());
52 }
53
54 template <class Up>
55 // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: declaration uses identifier 'Up', which is not a reserved identifier [bugprone-reserved-identifier]
56 // CHECK-FIXES: {{^}}template <class _Up>{{$}}
57 inline reference_wrapper<const Up>
58 cref(const Up &u) noexcept {
59 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: declaration uses identifier 'u', which is not a reserved identifier [bugprone-reserved-identifier]
60 // CHECK-FIXES: {{^}}cref(const _Up &__u) noexcept {{{$}}
61 return reference_wrapper<const Up>(u);
62 }
63
64 template <class _Tp>
65 inline reference_wrapper<_Tp>
66 cref(reference_wrapper<const _Tp> __t) noexcept {
67 return cref(__t.get());
68 }
69
70 } // namespace std