1 // RUN: %check_clang_tidy %s abseil-no-internal-dependencies %t,  -- -- -I %S/Inputs
2 // RUN: clang-tidy -checks='-*, abseil-no-internal-dependencies' -header-filter='.*' %s -- -I %S/Inputs 2>&1 | FileCheck %s
3 
4 #include "absl/strings/internal-file.h"
5 #include "absl/flags/internal-file.h"
6 // CHECK-NOT: warning:
7 
8 #include "absl/external-file.h"
9 // CHECK: absl/external-file.h:6:24: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil [abseil-no-internal-dependencies]
10 
DirectAcess()11 void DirectAcess() {
12   absl::strings_internal::InternalFunction();
13   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil
14 
15   absl::strings_internal::InternalTemplateFunction<std::string>("a");
16   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil
17 }
18 
19 class FriendUsage {
20   friend struct absl::container_internal::InternalStruct;
21   // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil
22 };
23 
24 namespace absl {
OpeningNamespace()25 void OpeningNamespace() {
26   strings_internal::InternalFunction();
27   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil
28 }
29 } // namespace absl
30 
31 // should not trigger warnings
CorrectUsage()32 void CorrectUsage() {
33   std::string Str = absl::StringsFunction("a");
34   absl::SomeContainer b;
35 }
36 
37 namespace absl {
38 SomeContainer b;
39 std::string Str = absl::StringsFunction("a");
40 } // namespace absl
41 
42 #define USE_EXTERNAL(x) absl::strings_internal::Internal##x()
43 
MacroUse()44 void MacroUse() {
45   USE_INTERNAL(Function); // no-warning
46   USE_EXTERNAL(Function);
47   // CHECK-MESSAGES: :[[@LINE-5]]:25: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil
48 }
49 
50 class A : absl::container_internal::InternalStruct {};
51 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil
52 
53 template <typename T>
54 class B : absl::container_internal::InternalTemplate<T> {};
55 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil
56 
57 template <typename T> class C : absl::container_internal::InternalTemplate<T> {
58 public:
Make(U * p)59   template <typename U> static C Make(U *p) { return C{}; }
60 };
61 // CHECK-MESSAGES: :[[@LINE-4]]:33: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil
62