brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.2 KiB · e0b2258 Raw
164 lines · cpp
1// RUN: %check_clang_tidy %s bugprone-forward-declaration-namespace %t2 3namespace {4// This is a declaration in a wrong namespace.5class T_A;6// CHECK-NOTES: :[[@LINE-1]]:7: warning: declaration 'T_A' is never referenced, but a declaration with the same name found in another namespace 'na' [bugprone-forward-declaration-namespace]7// CHECK-NOTES: note: a declaration of 'T_A' is found here8// CHECK-NOTES: :[[@LINE-3]]:7: warning: no definition found for 'T_A', but a definition with the same name 'T_A' found in another namespace '(global)' [bugprone-forward-declaration-namespace]9// CHECK-NOTES: note: a definition of 'T_A' is found here10}11 12namespace na {13// This is a declaration in a wrong namespace.14class T_A;15// CHECK-NOTES: :[[@LINE-1]]:7: warning: declaration 'T_A' is never referenced, but a declaration with the same name found in another namespace '(anonymous)'16// CHECK-NOTES: note: a declaration of 'T_A' is found here17// CHECK-NOTES: :[[@LINE-3]]:7: warning: no definition found for 'T_A', but a definition with the same name 'T_A' found in another namespace '(global)'18// CHECK-NOTES: note: a definition of 'T_A' is found here19}20 21class T_A;22 23class T_A {24  int x;25};26 27class NESTED;28// CHECK-NOTES: :[[@LINE-1]]:7: warning: no definition found for 'NESTED', but a definition with the same name 'NESTED' found in another namespace '(anonymous namespace)::nq::(anonymous)'29// CHECK-NOTES: note: a definition of 'NESTED' is found here30 31namespace {32namespace nq {33namespace {34class NESTED {};35}36}37}38 39namespace na {40class T_B;41// CHECK-NOTES: :[[@LINE-1]]:7: warning: declaration 'T_B' is never referenced, but a declaration with the same name found in another namespace 'nb'42// CHECK-NOTES: note: a declaration of 'T_B' is found here43// CHECK-NOTES: :[[@LINE-3]]:7: warning: no definition found for 'T_B', but a definition with the same name 'T_B' found in another namespace 'nb'44// CHECK-NOTES: note: a definition of 'T_B' is found here45}46 47namespace nb {48class T_B;49}50 51namespace nb {52class T_B {53  int x;54};55}56 57namespace na {58class T_B;59// CHECK-NOTES: :[[@LINE-1]]:7: warning: declaration 'T_B' is never referenced, but a declaration with the same name found in another namespace 'nb'60// CHECK-NOTES: note: a declaration of 'T_B' is found here61// CHECK-NOTES: :[[@LINE-3]]:7: warning: no definition found for 'T_B', but a definition with the same name 'T_B' found in another namespace 'nb'62// CHECK-NOTES: note: a definition of 'T_B' is found here63}64 65// A simple forward declaration. Although it is never used, but no declaration66// with the same name is found in other namespace.67class OUTSIDER;68 69namespace na {70// This class is referenced declaration, we don't generate warning.71class OUTSIDER_1;72}73 74void f(na::OUTSIDER_1);75 76namespace nc {77// This class is referenced as friend in OOP.78class OUTSIDER_1;79 80class OOP {81  friend struct OUTSIDER_1;82};83}84 85namespace nd {86class OUTSIDER_1;87void f(OUTSIDER_1 *);88}89 90namespace nb {91class OUTSIDER_1;92// CHECK-NOTES: :[[@LINE-1]]:7: warning: declaration 'OUTSIDER_1' is never referenced, but a declaration with the same name found in another namespace 'na'93// CHECK-NOTES: note: a declaration of 'OUTSIDER_1' is found here94}95 96 97namespace na {98template<typename T>99class T_C;100}101 102namespace nb {103// FIXME: this is an error, but we don't consider template class declaration104// now.105template<typename T>106class T_C;107}108 109namespace na {110template<typename T>111class T_C {112  int x;113};114}115 116namespace na {117 118template <typename T>119class T_TEMP {120  template <typename _Tp1>121  struct rebind { typedef T_TEMP<_Tp1> other; };122};123 124// We ignore class template specialization.125template class T_TEMP<char>;126}127 128namespace nb {129 130template <typename T>131class T_TEMP_1 {132  template <typename _Tp1>133  struct rebind { typedef T_TEMP_1<_Tp1> other; };134};135 136// We ignore class template specialization.137extern template class T_TEMP_1<char>;138}139 140namespace nd {141class D;142// CHECK-NOTES: :[[@LINE-1]]:7: warning: declaration 'D' is never referenced, but a declaration with the same name found in another namespace 'nd::ne'143// CHECK-NOTES: note: a declaration of 'D' is found here144}145 146namespace nd {147namespace ne {148class D;149}150}151 152int f(nd::ne::D &d);153 154 155// This should be ignored by the check.156template <typename... Args>157class Observer {158  class Impl;159};160 161template <typename... Args>162class Observer<Args...>::Impl {163};164