• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %check_clang_tidy %s bugprone-reserved-identifier %t -- \
2 // RUN:   -config='{CheckOptions: [ \
3 // RUN:     {key: bugprone-reserved-identifier.Invert, value: 1}, \
4 // RUN:     {key: bugprone-reserved-identifier.AllowedIdentifiers, value: std;reference_wrapper;ref;cref;type;get}, \
5 // RUN:   ]}' -- \
6 // RUN:   -I%S/Inputs/bugprone-reserved-identifier \
7 // RUN:   -isystem %S/Inputs/bugprone-reserved-identifier/system
8 
9 namespace std {
10 
__f()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:
reference_wrapper(type & __f)35   reference_wrapper(type &__f)
36       : __f_(&__f) {}
37   // access
operator type&() const38   operator type &() const { return *__f_; }
get() const39   type &get() const { return *__f_; }
40 };
41 
42 template <class _Tp>
43 inline reference_wrapper<_Tp>
ref(_Tp & __t)44 ref(_Tp &__t) noexcept {
45   return reference_wrapper<_Tp>(__t);
46 }
47 
48 template <class _Tp>
49 inline reference_wrapper<_Tp>
ref(reference_wrapper<_Tp> __t)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>
cref(const Up & u)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>
cref(reference_wrapper<const _Tp> __t)66 cref(reference_wrapper<const _Tp> __t) noexcept {
67   return cref(__t.get());
68 }
69 
70 } // namespace std
71