diff --git a/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp b/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp --- a/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp +++ b/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; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/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 + ` when using + anonymous structs or classes. + - Fixed an issue in :doc:`google-readability-avoid-underscore-in-googletest-name ` when using ``DISABLED_`` in the test suite name. diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/readability/static-accessed-through-instance.cpp +++ b/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