1 // RUN: %clang_cc1 -std=c++2a -verify %s -pedantic
2 
3 template<typename T> struct Template {};
4 
5 struct Linkage1 { struct Inner {}; };
6 typedef struct { struct Inner {}; } Linkage2;
7 
8 typedef struct {} const NoLinkage1;
__anonff993c5b0302null9 auto x = [] {};
10 typedef decltype(x) NoLinkage2;
__anonff993c5b0402null11 auto f() { return [] {}; }
12 typedef decltype(f()) NoLinkage3;
13 
g()14 inline auto g() { return [] {}; }
15 typedef decltype(g()) VisibleNoLinkage1;
__anonff993c5b0602null16 inline auto y = [] {};
17 typedef decltype(y) VisibleNoLinkage2;
h()18 inline auto h() { struct {} x; return x; }
19 typedef decltype(h()) VisibleNoLinkage3;
20 
21 extern Linkage1 linkage1v;
22 extern Linkage1::Inner linkage1iv;
23 extern Linkage2 linkage2v;
24 extern Linkage2::Inner linkage2iv;
25 extern Template<Linkage1> linkaget1v;
26 extern Linkage1 linkage1f();
27 void linkage2f(Linkage2);
28 
use_linkage()29 void use_linkage() {
30   &linkage1v, &linkage1iv, &linkage2v, &linkage2iv, &linkaget1v; // expected-warning 5{{unused}}
31   linkage1f();
32   linkage2f({});
33 }
34 
35 extern NoLinkage1 no_linkage1(); // expected-error {{function 'no_linkage1' is used but not defined in this translation unit}}
36 extern NoLinkage2 no_linkage2(); // expected-error {{function 'no_linkage2' is used but not defined in this translation unit}}
37 extern NoLinkage3 no_linkage3(); // expected-error {{function 'no_linkage3' is used but not defined in this translation unit}}
38 
use_no_linkage()39 void use_no_linkage() {
40   no_linkage1(); // expected-note {{used here}}
41   no_linkage2(); // expected-note {{used here}}
42   no_linkage3(); // expected-note {{used here}}
43 }
44 
45 extern VisibleNoLinkage1 visible_no_linkage1(); // expected-warning {{ISO C++ requires a definition}}
46 extern VisibleNoLinkage2 visible_no_linkage2(); // expected-warning {{ISO C++ requires a definition}}
47 extern VisibleNoLinkage3 visible_no_linkage3(); // expected-warning {{ISO C++ requires a definition}}
48 
use_visible_no_linkage()49 void use_visible_no_linkage() {
50   visible_no_linkage1(); // expected-note {{used here}}
51   visible_no_linkage2(); // expected-note {{used here}}
52   visible_no_linkage3(); // expected-note {{used here}}
53 }
54 
55 namespace {
56   struct InternalLinkage {};
57 }
58 InternalLinkage internal_linkage(); // expected-error {{used but not defined}}
use_internal_linkage()59 void use_internal_linkage() {
60   internal_linkage(); // expected-note {{used here}}
61 }
62 
63 extern inline int not_defined; // expected-error {{not defined}}
64 extern inline int defined_after_use;
use_inline_vars()65 void use_inline_vars() {
66   not_defined = 1; // expected-note {{used here}}
67   defined_after_use = 2;
68 }
69 inline int defined_after_use;
70 
71 namespace {
72   template<typename T> struct A {
73     static const int n;
74   };
75   template<typename T> const int A<T>::n = 3;
76   static_assert(A<int>::n == 3);
77   int k = A<float>::n;
78 }
79