]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaCXX/linkage2.cpp
Vendor import of clang tags/RELEASE_33/final r183502 (effectively, 3.3
[FreeBSD/FreeBSD.git] / test / SemaCXX / linkage2.cpp
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -fmodules %s
3
4 namespace test1 {
5   int x; // expected-note {{previous definition is here}}
6   static int y;
7   void f() {} // expected-note {{previous definition is here}}
8
9   extern "C" {
10     extern int x; // expected-error {{declaration of 'x' has a different language linkage}}
11     extern int y; // OK, has internal linkage, so no language linkage.
12     void f(); // expected-error {{declaration of 'f' has a different language linkage}}
13   }
14 }
15
16 // This is OK. Both test2_f don't have language linkage since they have
17 // internal linkage.
18 extern "C" {
19   static void test2_f() {
20   }
21   static void test2_f(int x) {
22   }
23 }
24
25 namespace test3 {
26   extern "C" {
27     namespace {
28       extern int x2;
29       void f2();
30     }
31   }
32   namespace {
33     int x2;
34     void f2() {}
35   }
36 }
37
38 namespace test4 {
39   void dummy() {
40     void Bar();
41     class A {
42       friend void Bar();
43     };
44   }
45 }
46
47 namespace test5 {
48   static void g();
49   void f()
50   {
51     void g();
52   }
53 }
54
55 // pr14898
56 namespace test6 {
57   template <class _Rp>
58   class __attribute__ ((__visibility__("default"))) shared_future;
59   template <class _Rp>
60   class future {
61     template <class> friend class shared_future;
62     shared_future<_Rp> share();
63   };
64   template <class _Rp> future<_Rp>
65   get_future();
66   template <class _Rp>
67   struct shared_future<_Rp&> {
68     shared_future(future<_Rp&>&& __f); // expected-warning {{rvalue references are a C++11 extension}}
69   };
70   void f() {
71     typedef int T;
72     get_future<int>();
73     typedef int& U;
74     shared_future<int&> f1 = get_future<int&>();
75   }
76 }
77
78 // This is OK. The variables have internal linkage and therefore no language
79 // linkage.
80 extern "C" {
81   static int test7_x;
82 }
83 extern "C++" {
84   extern int test7_x;
85 }
86 extern "C++" {
87   static int test7_y;
88 }
89 extern "C" {
90   extern int test7_y;
91 }
92 extern "C" { typedef int test7_F(); static test7_F test7_f; }
93 extern "C++" { extern test7_F test7_f; }
94
95 // FIXME: This should be invalid. The function has no language linkage, but
96 // the function type has, so this is redeclaring the function with a different
97 // type.
98 extern "C++" {
99   static void test8_f();
100 }
101 extern "C" {
102   extern void test8_f();
103 }
104 extern "C" {
105   static void test8_g();
106 }
107 extern "C++" {
108   extern void test8_g();
109 }
110
111 extern "C" {
112   void __attribute__((overloadable)) test9_f(int c); // expected-note {{previous declaration is here}}
113 }
114 extern "C++" {
115   void __attribute__((overloadable)) test9_f(int c); // expected-error {{declaration of 'test9_f' has a different language linkage}}
116 }
117
118 extern "C" {
119   void __attribute__((overloadable)) test10_f(int);
120   void __attribute__((overloadable)) test10_f(double);
121 }
122
123 extern "C" {
124   void test11_f() {
125     void  __attribute__((overloadable)) test11_g(int);
126     void  __attribute__((overloadable)) test11_g(double);
127   }
128 }
129
130 namespace test12 {
131   const int n = 0;
132   extern const int n;
133   void f() {
134     extern const int n;
135   }
136 }
137
138 namespace test13 {
139   static void a(void);
140   extern void a();
141   static void a(void) {}
142 }
143
144 namespace test14 {
145   namespace {
146     void a(void); // expected-note {{previous declaration is here}}
147     static void a(void) {} // expected-error {{static declaration of 'a' follows non-static declaration}}
148   }
149 }
150
151 namespace test15 {
152   const int a = 5; // expected-note {{previous definition is here}}
153   static const int a; // expected-error {{redefinition of 'a'}}
154 }
155
156 namespace test16 {
157   extern "C" {
158     class Foo {
159       int x;
160       friend int bar(Foo *y);
161     };
162     int bar(Foo *y) {
163       return y->x;
164     }
165   }
166 }