[clang-tools-extra] r341643 - [clang-tidy] Abseil: Allow macros inside of absl to use internal absl things

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 7 02:25:23 PDT 2018


Author: d0k
Date: Fri Sep  7 02:25:23 2018
New Revision: 341643

URL: http://llvm.org/viewvc/llvm-project?rev=341643&view=rev
Log:
[clang-tidy] Abseil: Allow macros inside of absl to use internal absl things

Modified:
    clang-tools-extra/trunk/clang-tidy/abseil/AbseilMatcher.h
    clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/strings/internal-file.h
    clang-tools-extra/trunk/test/clang-tidy/abseil-no-internal-dependencies.cpp

Modified: clang-tools-extra/trunk/clang-tidy/abseil/AbseilMatcher.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/AbseilMatcher.h?rev=341643&r1=341642&r2=341643&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/abseil/AbseilMatcher.h (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/AbseilMatcher.h Fri Sep  7 02:25:23 2018
@@ -33,7 +33,7 @@ AST_POLYMORPHIC_MATCHER(
     isInAbseilFile, AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc,
                                                     NestedNameSpecifierLoc)) {
   auto &SourceManager = Finder->getASTContext().getSourceManager();
-  SourceLocation Loc = Node.getBeginLoc();
+  SourceLocation Loc = SourceManager.getSpellingLoc(Node.getBeginLoc());
   if (Loc.isInvalid())
     return false;
   const FileEntry *FileEntry =

Modified: clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/strings/internal-file.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/strings/internal-file.h?rev=341643&r1=341642&r2=341643&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/strings/internal-file.h (original)
+++ clang-tools-extra/trunk/test/clang-tidy/Inputs/absl/strings/internal-file.h Fri Sep  7 02:25:23 2018
@@ -31,3 +31,5 @@ class FriendUsageInternal {
 namespace absl {
 void OpeningNamespaceInternally() { strings_internal::InternalFunction(); }
 } // namespace absl
+
+#define USE_INTERNAL(x) absl::strings_internal::Internal##x()

Modified: clang-tools-extra/trunk/test/clang-tidy/abseil-no-internal-dependencies.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-no-internal-dependencies.cpp?rev=341643&r1=341642&r2=341643&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/abseil-no-internal-dependencies.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/abseil-no-internal-dependencies.cpp Fri Sep  7 02:25:23 2018
@@ -37,3 +37,11 @@ namespace absl {
 SomeContainer b;
 std::string Str = absl::StringsFunction("a");
 } // namespace absl
+
+#define USE_EXTERNAL(x) absl::strings_internal::Internal##x()
+
+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
+}




More information about the cfe-commits mailing list