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(D)) { if (Decl->isMain() || !Decl->isUserProvided() || - Decl->size_overridden_methods() > 0) + Decl->size_overridden_methods() > 0 || Decl->hasAttr()) return SK_Invalid; // If this method has the same name as any base method, this is likely 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 { @@ -293,6 +297,9 @@ void BadBaseMethod() override {} // CHECK-FIXES: {{^}} void v_Bad_Base_Method() override {} + void BadBaseMethodNoAttr() /* override */ {} + // CHECK-FIXES: {{^}} void v_Bad_Base_Method_No_Attr() /* override */ {} + void foo() { BadBaseMethod(); // CHECK-FIXES: {{^}} v_Bad_Base_Method(); @@ -302,12 +309,79 @@ // 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(); + this->BadBaseMethodNoAttr(); + // CHECK-FIXES: {{^}} this->v_Bad_Base_Method_No_Attr(); + AOverridden::BadBaseMethodNoAttr(); + // CHECK-FIXES: {{^}} AOverridden::v_Bad_Base_Method_No_Attr(); + COverriding::BadBaseMethodNoAttr(); + // CHECK-FIXES: {{^}} COverriding::v_Bad_Base_Method_No_Attr(); } }; -void VirtualCall(AOverridden &a_vItem) { +// Same test as above, now with a dependent base class. +template +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 +class CTOverriding : public ATOverridden { + // 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 +void VirtualCall(AOverridden &a_vItem, ATOverridden &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 +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 +class CTIOverriding : public ATIOverridden { +public: + // Overriding a badly-named base isn't a new violation. + void BadBaseMethod() override {} + // CHECK-FIXES: {{^}} void v_Bad_Base_Method() override {} +}; + +template class CTIOverriding; + +void VirtualCallI(ATIOverridden& a_vItem, CTIOverriding& a_vCitem) { a_vItem.BadBaseMethod(); // CHECK-FIXES: {{^}} a_vItem.v_Bad_Base_Method(); + + a_vCitem.BadBaseMethod(); + // CHECK-FIXES: {{^}} a_vCitem.v_Bad_Base_Method(); } template