fwolff updated this revision to Diff 387121.
fwolff added a comment.
Thanks for your comments @salman-javed-nz! I have expanded the tests now
according to your suggestions.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113830/new/
https://reviews.llvm.org/D113830
Files:
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp
@@ -285,6 +285,10 @@
virtual void BadBaseMethod() = 0;
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for virtual method 'BadBaseMethod'
// CHECK-FIXES: {{^}} virtual void v_Bad_Base_Method() = 0;
+
+ virtual void BadBaseMethodNoAttr() = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for virtual method 'BadBaseMethodNoAttr'
+ // CHECK-FIXES: {{^}} virtual void v_Bad_Base_Method_No_Attr() = 0;
};
class COverriding : public AOverridden {
@@ -292,6 +296,8 @@
// Overriding a badly-named base isn't a new violation.
void BadBaseMethod() override {}
// CHECK-FIXES: {{^}} void v_Bad_Base_Method() override {}
+ void BadBaseMethodNoAttr() {}
+ // CHECK-FIXES: {{^}} void v_Bad_Base_Method_No_Attr() {}
void foo() {
BadBaseMethod();
@@ -302,14 +308,66 @@
// CHECK-FIXES: {{^}} AOverridden::v_Bad_Base_Method();
COverriding::BadBaseMethod();
// CHECK-FIXES: {{^}} COverriding::v_Bad_Base_Method();
+
+ BadBaseMethodNoAttr();
+ // CHECK-FIXES: {{^}} v_Bad_Base_Method_No_Attr();
}
};
-void VirtualCall(AOverridden &a_vItem) {
+// Same test as above, now with a dependent base class.
+template<typename some_t>
+class ATOverridden {
+public:
+ virtual void BadBaseMethod() = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for virtual method 'BadBaseMethod'
+ // CHECK-FIXES: {{^}} virtual void v_Bad_Base_Method() = 0;
+
+ virtual void BadBaseMethodNoAttr() = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for virtual method 'BadBaseMethodNoAttr'
+ // CHECK-FIXES: {{^}} virtual void v_Bad_Base_Method_No_Attr() = 0;
+};
+
+template<typename some_t>
+class CTOverriding : public ATOverridden<some_t> {
+ // Overriding a badly-named base isn't a new violation.
+ // FIXME: The fixes from the base class should be propagated to the derived class here
+ // (note that there could be specializations of the template base class, though)
+ void BadBaseMethod() override{}
+
+ // Without the "override" attribute, and due to the dependent base class, it is not
+ // known whether this method overrides anything, so we get the warning here.
+ virtual void BadBaseMethodNoAttr() {};
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for virtual method 'BadBaseMethodNoAttr'
+ // CHECK-FIXES: {{^}} virtual void v_Bad_Base_Method_No_Attr() {};
+};
+
+template<typename some_t>
+void VirtualCall(AOverridden &a_vItem, ATOverridden<some_t> &a_vTitem) {
a_vItem.BadBaseMethod();
// CHECK-FIXES: {{^}} a_vItem.v_Bad_Base_Method();
+
+ // FIXME: The fixes from ATOverridden should be propagated to the following call
+ a_vTitem.BadBaseMethod();
}
+// Same test as above, now with a dependent base class that is instantiated below.
+template<typename some_t>
+class ATIOverridden {
+public:
+ virtual void BadBaseMethod() = 0;
+ // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: invalid case style for virtual method 'BadBaseMethod'
+ // CHECK-FIXES: {{^}} virtual void v_Bad_Base_Method() = 0;
+};
+
+template<typename some_t>
+class CTIOverriding : public ATIOverridden<some_t> {
+ // Overriding a badly-named base isn't a new violation.
+ void BadBaseMethod() override{}
+ // CHECK-FIXES: {{^}} void v_Bad_Base_Method() override{}
+};
+
+template class CTIOverriding<int>;
+
template <typename derived_t>
class CRTPBase {
public:
Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1257,7 +1257,7 @@
if (const auto *Decl = dyn_cast<CXXMethodDecl>(D)) {
if (Decl->isMain() || !Decl->isUserProvided() ||
- Decl->size_overridden_methods() > 0)
+ Decl->size_overridden_methods() > 0 || Decl->hasAttr<OverrideAttr>())
return SK_Invalid;
// If this method has the same name as any base method, this is likely
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits