xref: /minix3/external/bsd/llvm/dist/clang/test/CXX/basic/basic.link/p7.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -verify -std=c++1y %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // Example from the standard.
4*f4a2713aSLionel Sambuc namespace X {
p()5*f4a2713aSLionel Sambuc   void p() {
6*f4a2713aSLionel Sambuc     q(); // expected-error {{undeclared}}
7*f4a2713aSLionel Sambuc     extern void q();
8*f4a2713aSLionel Sambuc   }
middle()9*f4a2713aSLionel Sambuc   void middle() {
10*f4a2713aSLionel Sambuc     q(); // expected-error {{undeclared}}
11*f4a2713aSLionel Sambuc   }
q()12*f4a2713aSLionel Sambuc   void q() { /*...*/ }
bottom()13*f4a2713aSLionel Sambuc   void bottom() {
14*f4a2713aSLionel Sambuc     q();
15*f4a2713aSLionel Sambuc   }
16*f4a2713aSLionel Sambuc }
17*f4a2713aSLionel Sambuc int q();
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc namespace Test1 {
f()20*f4a2713aSLionel Sambuc   void f() {
21*f4a2713aSLionel Sambuc     extern int a; // expected-note {{previous}}
22*f4a2713aSLionel Sambuc     int g(void); // expected-note {{previous}}
23*f4a2713aSLionel Sambuc   }
24*f4a2713aSLionel Sambuc   double a; // expected-error {{different type: 'double' vs 'int'}}
25*f4a2713aSLionel Sambuc   double g(); // expected-error {{differ only in their return type}}
26*f4a2713aSLionel Sambuc }
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc namespace Test2 {
f()29*f4a2713aSLionel Sambuc   void f() {
30*f4a2713aSLionel Sambuc     extern int a; // expected-note {{previous}}
31*f4a2713aSLionel Sambuc     int g(void); // expected-note {{previous}}
32*f4a2713aSLionel Sambuc   }
h()33*f4a2713aSLionel Sambuc   void h() {
34*f4a2713aSLionel Sambuc     extern double a; // expected-error {{different type: 'double' vs 'int'}}
35*f4a2713aSLionel Sambuc     double g(void); // expected-error {{differ only in their return type}}
36*f4a2713aSLionel Sambuc   }
37*f4a2713aSLionel Sambuc }
38*f4a2713aSLionel Sambuc 
39*f4a2713aSLionel Sambuc namespace Test3 {
f()40*f4a2713aSLionel Sambuc   constexpr void (*f())() {
41*f4a2713aSLionel Sambuc     void h();
42*f4a2713aSLionel Sambuc     return &h;
43*f4a2713aSLionel Sambuc   }
g()44*f4a2713aSLionel Sambuc   constexpr void (*g())() {
45*f4a2713aSLionel Sambuc     void h();
46*f4a2713aSLionel Sambuc     return &h;
47*f4a2713aSLionel Sambuc   }
48*f4a2713aSLionel Sambuc   static_assert(f() == g(), "");
49*f4a2713aSLionel Sambuc }
50*f4a2713aSLionel Sambuc 
51*f4a2713aSLionel Sambuc namespace Test4 {
52*f4a2713aSLionel Sambuc   template<typename T>
f()53*f4a2713aSLionel Sambuc   constexpr void (*f())() {
54*f4a2713aSLionel Sambuc     void h();
55*f4a2713aSLionel Sambuc     return &h;
56*f4a2713aSLionel Sambuc   }
57*f4a2713aSLionel Sambuc   static_assert(f<int>() == f<char>(), "");
58*f4a2713aSLionel Sambuc   void h();
59*f4a2713aSLionel Sambuc   static_assert(f<int>() == &h, "");
60*f4a2713aSLionel Sambuc }
61*f4a2713aSLionel Sambuc 
62*f4a2713aSLionel Sambuc namespace Test5 {
f()63*f4a2713aSLionel Sambuc   constexpr auto f() -> void (*)() {
64*f4a2713aSLionel Sambuc     void g();
65*f4a2713aSLionel Sambuc     struct X {
66*f4a2713aSLionel Sambuc       friend void g();
67*f4a2713aSLionel Sambuc       static constexpr auto h() -> void (*)() { return g; }
68*f4a2713aSLionel Sambuc     };
69*f4a2713aSLionel Sambuc     return X::h();
70*f4a2713aSLionel Sambuc   }
71*f4a2713aSLionel Sambuc   void g();
72*f4a2713aSLionel Sambuc   static_assert(f() == g, "");
73*f4a2713aSLionel Sambuc }
74