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