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