rogeeff created this revision. Herald added a subscriber: mgehre. Herald added a project: clang. rogeeff added a reviewer: EricWF.
This change makes following modifications: - If reference originated from macro expansion, we report location inside of the macro instead of location where macro is referenced - If for any reason deduced location is not correct we silently ignore it. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D72484 Files: clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp clang-tools-extra/test/clang-tidy/checkers/Inputs/absl/strings/internal-file.h clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp Index: clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp +++ clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp @@ -44,5 +44,18 @@ void MacroUse() { USE_INTERNAL(Function); // no-warning USE_EXTERNAL(Function); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil + // CHECK-MESSAGES: :[[@LINE-5]]:25: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil } + +class A : absl::container_internal::InternalStruct {}; +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil + +template <typename T> +class B : absl::container_internal::InternalTemplate<T> {}; +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil + +template <typename T> class C : absl::container_internal::InternalTemplate<T> { +public: + template <typename U> static C Make(U *p) { return C{}; } +}; +// CHECK-MESSAGES: :[[@LINE-4]]:33: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/absl/strings/internal-file.h =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/Inputs/absl/strings/internal-file.h +++ clang-tools-extra/test/clang-tidy/checkers/Inputs/absl/strings/internal-file.h @@ -15,6 +15,8 @@ namespace container_internal { struct InternalStruct {}; + +template <typename T> struct InternalTemplate {}; } // namespace container_internal } // namespace absl Index: clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp +++ clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp @@ -37,7 +37,13 @@ const auto *InternalDependency = Result.Nodes.getNodeAs<NestedNameSpecifierLoc>("InternalDep"); - diag(InternalDependency->getBeginLoc(), + auto loc_at_fault = + Result.SourceManager->getSpellingLoc(InternalDependency->getBeginLoc()); + + if (!loc_at_fault.isValid()) + return; + + diag(loc_at_fault, "do not reference any 'internal' namespaces; those implementation " "details are reserved to Abseil"); }
Index: clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp +++ clang-tools-extra/test/clang-tidy/checkers/abseil-no-internal-dependencies.cpp @@ -44,5 +44,18 @@ void MacroUse() { USE_INTERNAL(Function); // no-warning USE_EXTERNAL(Function); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil + // CHECK-MESSAGES: :[[@LINE-5]]:25: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil } + +class A : absl::container_internal::InternalStruct {}; +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil + +template <typename T> +class B : absl::container_internal::InternalTemplate<T> {}; +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil + +template <typename T> class C : absl::container_internal::InternalTemplate<T> { +public: + template <typename U> static C Make(U *p) { return C{}; } +}; +// CHECK-MESSAGES: :[[@LINE-4]]:33: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/absl/strings/internal-file.h =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/Inputs/absl/strings/internal-file.h +++ clang-tools-extra/test/clang-tidy/checkers/Inputs/absl/strings/internal-file.h @@ -15,6 +15,8 @@ namespace container_internal { struct InternalStruct {}; + +template <typename T> struct InternalTemplate {}; } // namespace container_internal } // namespace absl Index: clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp +++ clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp @@ -37,7 +37,13 @@ const auto *InternalDependency = Result.Nodes.getNodeAs<NestedNameSpecifierLoc>("InternalDep"); - diag(InternalDependency->getBeginLoc(), + auto loc_at_fault = + Result.SourceManager->getSpellingLoc(InternalDependency->getBeginLoc()); + + if (!loc_at_fault.isValid()) + return; + + diag(loc_at_fault, "do not reference any 'internal' namespaces; those implementation " "details are reserved to Abseil"); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits