Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / compilerplugins / clang / test / external.cxx
blob77bb53c6b25050a49cdc4c2b50b7f56a5df69343
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/config.h>
12 #include <vector>
14 #include "external.hxx"
16 int n0; // no warning, see external.hxx
18 // expected-error@+1 {{externally available entity 'n1' is not previously declared in an included file (if it is only used in this translation unit, make it static or put it in an unnamed namespace; otherwise, provide a declaration of it in an included file) [loplugin:external]}}
19 int n1 = 0;
20 // expected-note@+1 {{another declaration is here [loplugin:external]}}
21 extern int n1;
23 int const n2 = 0; // no warning, internal linkage
25 constexpr int n3 = 0; // no warning, internal linkage
27 static int n4; // no warning, internal linkage
29 // expected-note@+1 {{another declaration is here [loplugin:external]}}
30 extern int n5;
31 // expected-error@+1 {{externally available entity 'n5' is not previously declared in an included file (if it is only used in this translation unit, make it static or put it in an unnamed namespace; otherwise, provide a declaration of it in an included file) [loplugin:external]}}
32 int n5;
34 // expected-note@+1 {{another declaration is here [loplugin:external]}}
35 extern "C" int n6;
36 // expected-error@+1 {{externally available entity 'n6' is not previously declared in an included file (if it is only used in this translation unit, make it static or put it in an unnamed namespace; otherwise, provide a declaration of it in an included file) [loplugin:external]}}
37 int n6;
39 extern "C" {
40 // expected-error@+1 {{externally available entity 'n7' is not previously declared in an included file (if it is only used in this translation unit, make it static or put it in an unnamed namespace; otherwise, provide a declaration of it in an included file) [loplugin:external]}}
41 int n7;
44 namespace
46 int u1; // no warning, internal linkage
48 static int u2; // no warning, internal linkage
50 extern "C" int u3;
51 int u3; // no warning, see the comment about DR1113 in compilerplugins/clang/external.cxx
53 extern "C" {
54 int u4; // no warning, internal linkage
58 namespace N
60 int v1; // no warning, see external.hxx
62 // expected-error@+1 {{externally available entity 'v2' is not previously declared in an included file (if it is only used in this translation unit, make it static or put it in an unnamed namespace; otherwise, provide a declaration of it in an included file) [loplugin:external]}}
63 int v2;
65 static int v3; // no warning, internal linkage
68 struct S
70 static int f()
72 static int s = 0;
73 return s;
76 static int m;
79 int S::m = 0; // no warning
81 int f(int a) // no warning about parameters
83 static int s = 0; // no warning about local static variables
84 ++s;
85 int b = a + s; // no warning about local variables
86 return b;
89 // expected-error@+1 {{externally available entity 'S1' is not previously declared in an included file (if it is only used in this translation unit, put it in an unnamed namespace; otherwise, provide a declaration of it in an included file) [loplugin:external]}}
90 struct S1
92 friend void f1() {} // no warning for injected function (no place where to mark it `static`)
93 template <typename> friend void ft1() {} // ...nor for injected function template
94 // expected-error@+1 {{externally available entity 'f2' is not previously declared in an included file (if it is only used in this translation unit, make it static; otherwise, provide a declaration of it in an included file) [loplugin:external]}}
95 friend void f2() {}
98 // expected-error@+1 {{externally available entity 'S2' is not previously declared in an included file (if it is only used in this translation unit, put it in an unnamed namespace; otherwise, provide a declaration of it in an included file) [loplugin:external]}}
99 struct S2
101 friend void f1();
102 template <typename> friend void ft1();
103 // expected-note@+1 {{another declaration is here [loplugin:external]}}
104 friend void f2();
107 static void g()
109 void f1();
110 // expected-note@+1 {{another declaration is here [loplugin:external]}}
111 void f2();
114 // expected-note@+1 {{another declaration is here [loplugin:external]}}
115 void f2();
117 namespace N
119 inline namespace I1
121 extern "C++" {
122 // expected-note@+1 {{another declaration is here [loplugin:external]}}
123 enum E : int;
125 // expected-error@+1 {{externally available entity 'E' is not previously declared in an included file (if it is only used in this translation unit, put it in an unnamed namespace; otherwise, provide a declaration of it in an included file) [loplugin:external]}}
126 enum E : int
132 // expected-note-re@+1 {{a function associating 'N{{(::I1)?}}::E' is declared here [loplugin:external]}}
133 static void g(std::vector<E>)
135 // expected-note@+1 {{another declaration is here [loplugin:external]}}
136 void f(E const*);
139 // expected-note-re@+1 {{a function associating 'N{{(::I1)?}}::E' is declared here [loplugin:external]}}
140 void f(E const*);
142 extern "C++" {
143 // expected-note-re@+1 {{a function associating 'N{{(::I1)?}}::E' is declared here [loplugin:external]}}
144 void fc(E const*);
147 // expected-error@+1 {{externally available entity 'S1' is not previously declared in an included file (if it is only used in this translation unit, put it in an unnamed namespace; otherwise, provide a declaration of it in an included file) [loplugin:external]}}
148 struct S1
150 struct S2;
151 // No note about associating function; injected friend function not found by ADL:
152 friend void f2(E const*);
153 // expected-note@+1 {{a function associating 'N::S1' is declared here [loplugin:external]}}
154 friend void h(S1);
157 // expected-error@+1 {{externally available entity 'S3' is not previously declared in an included file (if it is only used in this translation unit, put it in an unnamed namespace; otherwise, provide a declaration of it in an included file) [loplugin:external]}}
158 struct S3
160 // expected-note@+1 {{another declaration is here [loplugin:external]}}
161 friend void h(S1);
164 inline namespace I2
166 // expected-note-re@+1 {{a function associating 'N{{(::I1)?}}::E' is declared here [loplugin:external]}}
167 void f3(E);
169 inline namespace I3
171 // expected-note-re@+1 {{a function associating 'N{{(::I1)?}}::E' is declared here [loplugin:external]}}
172 void f4(E);
177 struct N::S1::S2
179 // expected-note@+1 {{another declaration is here [loplugin:external]}}
180 friend void f(E const*);
183 int main()
185 (void)n2;
186 (void)n3;
187 (void)n4;
188 (void)u1;
189 (void)u2;
190 (void)N::v3;
191 g();
192 (void)&N::g;
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */