AMS21 created this revision. AMS21 added reviewers: PiotrZSL, njames93, Eugene.Zelenko. Herald added subscribers: carlosgalvezp, xazax.hun. Herald added a project: All. AMS21 requested review of this revision. Herald added a project: clang-tools-extra. Herald added a subscriber: cfe-commits.
Previously we would provide a fixit which looked like this `unnamed struct at ...::f()` but which is obviously not valid C/C++. Since there is no real nice way to accesses a static function from an anonymous struct anyways we simply ignore all anonymous structs. Fixes llvm#61736 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D147411 Files: clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp Index: clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp +++ clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp @@ -285,3 +285,27 @@ // CHECK-MESSAGES-NOT: :[[@LINE-1]]:10: warning: static member } // namespace Bugzilla_48758 + +// https://github.com/llvm/llvm-project/issues/61736 +namespace llvm_issue_61736 +{ + +struct { + static void f() {} +} AnonStruct, *AnonStructPointer; + +class { + public: + static void f() {} +} AnonClass, *AnonClassPointer; + +void testAnonymousStructAndClass() +{ + AnonStruct.f(); + AnonStructPointer->f(); + + AnonClass.f(); + AnonClassPointer->f(); +} + +} // namespace llvm_issue_61736 Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -267,6 +267,10 @@ string for ``Prefix`` or ``Suffix`` options could result in the style not being used. +- Fixed an issue in :doc:`readability-static-accessed-through-instance + <clang-tidy/checks/readability/static-accessed-through-instance>` when using + anonymous structs or classes. + - Fixed an issue in :doc:`google-readability-avoid-underscore-in-googletest-name <clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name>` when using ``DISABLED_`` in the test suite name. Index: clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp +++ clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp @@ -74,6 +74,10 @@ std::string BaseTypeName = BaseType.getAsString(PrintingPolicyWithSupressedTag); + // Ignore anonymous structs/classes + if (StringRef(BaseTypeName).contains("(unnamed ")) + return; + // Do not warn for CUDA built-in variables. if (StringRef(BaseTypeName).startswith("__cuda_builtin_")) return;
Index: clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp +++ clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp @@ -285,3 +285,27 @@ // CHECK-MESSAGES-NOT: :[[@LINE-1]]:10: warning: static member } // namespace Bugzilla_48758 + +// https://github.com/llvm/llvm-project/issues/61736 +namespace llvm_issue_61736 +{ + +struct { + static void f() {} +} AnonStruct, *AnonStructPointer; + +class { + public: + static void f() {} +} AnonClass, *AnonClassPointer; + +void testAnonymousStructAndClass() +{ + AnonStruct.f(); + AnonStructPointer->f(); + + AnonClass.f(); + AnonClassPointer->f(); +} + +} // namespace llvm_issue_61736 Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -267,6 +267,10 @@ string for ``Prefix`` or ``Suffix`` options could result in the style not being used. +- Fixed an issue in :doc:`readability-static-accessed-through-instance + <clang-tidy/checks/readability/static-accessed-through-instance>` when using + anonymous structs or classes. + - Fixed an issue in :doc:`google-readability-avoid-underscore-in-googletest-name <clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name>` when using ``DISABLED_`` in the test suite name. Index: clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp +++ clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp @@ -74,6 +74,10 @@ std::string BaseTypeName = BaseType.getAsString(PrintingPolicyWithSupressedTag); + // Ignore anonymous structs/classes + if (StringRef(BaseTypeName).contains("(unnamed ")) + return; + // Do not warn for CUDA built-in variables. if (StringRef(BaseTypeName).startswith("__cuda_builtin_")) return;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits